Search in sources :

Example 1 with HashFunction

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);
}
Also used : HashFunction(org.neo4j.hashing.HashFunction)

Example 2 with HashFunction

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);
}
Also used : SchemaUserDescription(org.neo4j.internal.schema.SchemaUserDescription) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) Iterables.stream(org.neo4j.internal.helpers.collection.Iterables.stream) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IndexSettingUtil(org.neo4j.graphdb.schema.IndexSettingUtil) Collectors.joining(java.util.stream.Collectors.joining) IndexType(org.neo4j.graphdb.schema.IndexType) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) RelationshipType(org.neo4j.graphdb.RelationshipType) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexSetting(org.neo4j.graphdb.schema.IndexSetting) HashFunction(org.neo4j.hashing.HashFunction) IndexConfig(org.neo4j.internal.schema.IndexConfig) HashFunction(org.neo4j.hashing.HashFunction)

Example 3 with HashFunction

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 + ".");
}
Also used : HashFunction(org.neo4j.hashing.HashFunction)

Example 4 with HashFunction

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)));
}
Also used : HashFunction(org.neo4j.hashing.HashFunction)

Aggregations

HashFunction (org.neo4j.hashing.HashFunction)4 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Map (java.util.Map)1 Collectors.joining (java.util.stream.Collectors.joining)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 Label (org.neo4j.graphdb.Label)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)1 IndexSetting (org.neo4j.graphdb.schema.IndexSetting)1 IndexSettingUtil (org.neo4j.graphdb.schema.IndexSettingUtil)1 IndexType (org.neo4j.graphdb.schema.IndexType)1 Iterables.stream (org.neo4j.internal.helpers.collection.Iterables.stream)1 IndexConfig (org.neo4j.internal.schema.IndexConfig)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 SchemaUserDescription (org.neo4j.internal.schema.SchemaUserDescription)1