ipldNodeHash function
- IPLDNode node
Order-independent hash for ipldNodeEquals-comparable nodes.
Implementation
int ipldNodeHash(IPLDNode node) {
switch (node.kind) {
case Kind.NULL:
return 0;
case Kind.BOOL:
return Object.hash(1, node.boolValue);
case Kind.INTEGER:
return Object.hash(2, node.intValue);
case Kind.BIG_INT:
return Object.hash(2, Object.hashAll(node.bigIntValue));
case Kind.FLOAT:
return Object.hash(3, node.floatValue);
case Kind.STRING:
return Object.hash(4, node.stringValue);
case Kind.BYTES:
return Object.hash(5, Object.hashAll(node.bytesValue));
case Kind.LINK:
return Object.hash(
6,
node.linkValue.codec,
Object.hashAll(node.linkValue.multihash),
);
case Kind.LIST:
return Object.hash(7, Object.hashAll(node.listValue.values));
case Kind.MAP:
var hash = 8;
for (final entry in node.mapValue.entries) {
hash ^= Object.hash(entry.key, ipldNodeHash(entry.value));
}
return hash;
// coverage:ignore-start
default:
return node.kind.hashCode;
// coverage:ignore-end
}
}