use of org.neo4j.hashing.HashFunction in project neo4j by neo4j.
the class LockVerificationMonitor method schemaNameResourceId.
private static long schemaNameResourceId(String schemaName) {
// Copy of ResourceIds.schemaNameResourceId, as that is not accessible from in here
final HashFunction hashFunc = HashFunction.incrementalXXH64();
long hash = hashFunc.initialise(0x0123456789abcdefL);
hash = schemaName.chars().asLongStream().reduce(hash, hashFunc::update);
return hashFunc.finalise(hash);
}
use of org.neo4j.hashing.HashFunction in project neo4j by neo4j.
the class IndexDefinitionImpl method hashCode.
@Override
public int hashCode() {
HashFunction hf = HashFunction.incrementalXXH64();
long hash = hf.initialise(31);
hash = hf.updateWithArray(hash, labels, label -> label.name().hashCode());
hash = hf.updateWithArray(hash, relTypes, relType -> relType.name().hashCode());
hash = hf.updateWithArray(hash, propertyKeys, String::hashCode);
return hf.toInt(hash);
}
use of org.neo4j.hashing.HashFunction in project neo4j by neo4j.
the class SchemaRule method generateName.
/**
* Generate a <em>deterministic</em> name for the given {@link SchemaDescriptorSupplier}.
*
* Only {@link SchemaRule} implementations, and {@link IndexPrototype}, are supported arguments for the schema descriptor supplier.
*
* @param rule The {@link SchemaDescriptorSupplier} to generate a name for.
* @param entityTokenNames The resolved names of the schema entity tokens, that is, label names or relationship type names.
* @param propertyNames The resolved property key names.
* @return A name.
*/
static String generateName(SchemaDescriptorSupplier rule, String[] entityTokenNames, String[] propertyNames) {
// NOTE to future maintainers: You probably want to avoid touching this function.
// Last time this was changed, we had some 400+ tests to update.
HashFunction hf = HashFunction.incrementalXXH64();
long key = hf.initialise(Boolean.hashCode(rule instanceof ConstraintDescriptor));
key = hf.update(key, rule.schema().entityType().ordinal());
key = hf.update(key, rule.schema().propertySchemaType().ordinal());
key = hf.updateWithArray(key, entityTokenNames, String::hashCode);
key = hf.updateWithArray(key, propertyNames, String::hashCode);
if (rule instanceof IndexRef<?>) {
IndexRef<?> indexRef = (IndexRef<?>) rule;
key = hf.update(key, indexRef.getIndexType().ordinal());
key = hf.update(key, Boolean.hashCode(indexRef.isUnique()));
return String.format("index_%x", hf.toInt(hf.finalise(key)));
}
if (rule instanceof ConstraintDescriptor) {
ConstraintDescriptor constraint = (ConstraintDescriptor) rule;
key = hf.update(key, constraint.type().ordinal());
return String.format("constraint_%x", hf.toInt(hf.finalise(key)));
}
throw new IllegalArgumentException("Don't know how to generate a name for this SchemaDescriptorSupplier implementation: " + rule + ".");
}
use of org.neo4j.hashing.HashFunction in project neo4j by neo4j.
the class Value method hashCode64.
public final long hashCode64() {
HashFunction xxh64 = HashFunction.incrementalXXH64();
// Arbitrary seed, but it must always be the same or hash values will change.
long seed = 1;
return xxh64.finalise(updateHash(xxh64, xxh64.initialise(seed)));
}
Aggregations