comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 14743:762c9aceb7d8

Add equals/hashCode methods
author Christian Wimmer <christian.wimmer@oracle.com>
date Tue, 25 Mar 2014 11:50:05 -0700
parents 5e04917e6616
children 1422f0bd55e3
comparison
equal deleted inserted replaced
14742:ed8533832ea4 14743:762c9aceb7d8
120 return unsafe.getDouble(node, offset); 120 return unsafe.getDouble(node, offset);
121 } else { 121 } else {
122 return unsafe.getObject(node, offset); 122 return unsafe.getObject(node, offset);
123 } 123 }
124 } 124 }
125
126 @Override
127 public int hashCode() {
128 return kind.hashCode() | type.hashCode() | name.hashCode() | ((Long) offset).hashCode();
129 }
130
131 @Override
132 public boolean equals(Object obj) {
133 if (obj instanceof NodeField) {
134 NodeField other = (NodeField) obj;
135 return offset == other.offset && name.equals(other.name) && type.equals(other.type) && kind.equals(other.kind);
136 }
137 return false;
138 }
125 } 139 }
126 140
127 /** 141 /**
128 * Information about a {@link Node} class. A single instance of this class is allocated for 142 * Information about a {@link Node} class. A single instance of this class is allocated for
129 * every subclass of {@link Node} that is used. 143 * every subclass of {@link Node} that is used.
195 return childOffsets; 209 return childOffsets;
196 } 210 }
197 211
198 public long[] getChildrenOffsets() { 212 public long[] getChildrenOffsets() {
199 return childrenOffsets; 213 return childrenOffsets;
214 }
215
216 @Override
217 public int hashCode() {
218 return Arrays.hashCode(fields) ^ Arrays.hashCode(childOffsets) ^ Arrays.hashCode(childrenOffsets) ^ ((Long) parentOffset).hashCode();
219 }
220
221 @Override
222 public boolean equals(Object obj) {
223 if (obj instanceof NodeClass) {
224 NodeClass other = (NodeClass) obj;
225 return Arrays.equals(fields, other.fields) && Arrays.equals(childOffsets, other.childOffsets) && Arrays.equals(childrenOffsets, other.childrenOffsets) &&
226 parentOffset == other.parentOffset;
227 }
228 return false;
200 } 229 }
201 } 230 }
202 231
203 static class NodeIterator implements Iterator<Node> { 232 static class NodeIterator implements Iterator<Node> {
204 233