001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.compilers.opt.ssa;
014
015 /**
016 * utility class: represents a pair of value numbers.
017 */
018 class ValueNumberPair implements Comparable<ValueNumberPair> {
019 /** the value number of an array pointer */
020 final int v1;
021 /** the value number of an array index */
022 final int v2;
023
024 /** Construct a pair from the given arguments */
025 ValueNumberPair(int v1, int v2) {
026 this.v1 = v1;
027 this.v2 = v2;
028 }
029
030 /** Copy a pair */
031 ValueNumberPair(ValueNumberPair p) {
032 this.v1 = p.v1;
033 this.v2 = p.v2;
034 }
035
036 public boolean equals(Object o) {
037 if (!(o instanceof ValueNumberPair)) {
038 return false;
039 }
040 ValueNumberPair p = (ValueNumberPair) o;
041 return (v1 == p.v1) && (v2 == p.v2);
042 }
043
044 public int hashCode() {
045 return v1 << 16 | v2;
046 }
047
048 public String toString() {
049 return "<" + v1 + "," + v2 + ">";
050 }
051
052 // total order over ValueNumberPairs
053 public int compareTo(ValueNumberPair p) {
054 if (v1 > p.v1) {
055 return 1;
056 } else if (v1 < p.v1) {
057 return -1;
058 } else if (v2 > p.v2) {
059 // v1 == p.v1
060 return 1;
061 } else if (v2 < p.v2) {
062 return -1;
063 } else {
064 // v2 == p.v2
065 return 0;
066 }
067 }
068 }