Search in sources :

Example 1 with ObjectIntHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap in project neo4j by neo4j.

the class DelegatingTokenHolder method createUnresolvedTokens.

private ObjectIntHashMap<String> createUnresolvedTokens(IntSet unresolvedIndexes, String[] names, int[] ids, boolean internal) throws KernelException {
    // First, we need to filter out all of the tokens that are already resolved, so we only create tokens for
    // indexes that are in the unresolvedIndexes set.
    // However, we also need to deal with duplicate token names. For any token index we decide needs to have a
    // token created, we will add a mapping from the token name, to the ids-index into which the token id will
    // be written. This is the 'createdTokens' map. It maps token names to indexes into the 'ids' array.
    // If we find that the 'created'Tokens' map already has an entry for a given name, then that name is a
    // duplicate, and we will need to "remap" it later, by reading the token id from the correct index in the
    // 'ids' array, and storing it at the indexes of the duplicates. This is what the 'remappingIndexes' map is
    // for. This is a map from 'a' to 'b', where both 'a' and 'b' are indexes into the 'ids' array, and where
    // the corresponding name for 'a' is a duplicate of the name for 'b', and where we have already decided
    // that we will create a token id for index 'b'. After the token ids have been created, we go through the
    // 'remappingIndexes' map, and for every '(a,b)' entry, we store the token id created for 'b' and 'ids'
    // index 'a'.
    ObjectIntHashMap<String> createdTokens = new ObjectIntHashMap<>();
    IntIntHashMap remappingIndexes = new IntIntHashMap();
    IntPredicate tokenCreateFilter = index -> {
        boolean needsCreate = unresolvedIndexes.contains(index);
        if (needsCreate) {
            // The name at this index is unresolved.
            String name = names[index];
            int creatingIndex = createdTokens.getIfAbsentPut(name, index);
            if (creatingIndex != index) {
                // This entry has a duplicate name, so we need to remap this entry instead of creating a token
                // for it.
                remappingIndexes.put(index, creatingIndex);
                needsCreate = false;
            }
        }
        return needsCreate;
    };
    // Create tokens for all the indexes that we don't filter out.
    tokenCreator.createTokens(names, ids, internal, tokenCreateFilter);
    // Remap duplicate tokens to the token id we created for the first instance of any duplicate token name.
    if (remappingIndexes.notEmpty()) {
        remappingIndexes.forEachKeyValue((index, creatingIndex) -> ids[index] = ids[creatingIndex]);
    }
    return createdTokens;
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) ALWAYS_TRUE_INT(org.neo4j.function.Predicates.ALWAYS_TRUE_INT) NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) IntIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap) IntPredicate(java.util.function.IntPredicate) ArrayList(java.util.ArrayList) IntSet(org.eclipse.collections.api.set.primitive.IntSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) List(java.util.List) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) KernelException(org.neo4j.exceptions.KernelException) ObjectIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap) NamedToken(org.neo4j.token.api.NamedToken) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) IntIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap) ObjectIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap) IntPredicate(java.util.function.IntPredicate)

Example 2 with ObjectIntHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap in project neo4j by neo4j.

the class LogCommandSerializationV3_0_10 method readMap.

private static MutableObjectIntMap<String> readMap(ReadableChannel channel) throws IOException {
    int size = getUnsignedShort(channel);
    MutableObjectIntMap<String> result = new ObjectIntHashMap<>(size);
    for (int i = 0; i < size; i++) {
        String key = read2bLengthAndString(channel);
        int id = getUnsignedShort(channel);
        if (key == null) {
            return null;
        }
        result.put(key, id);
    }
    return result;
}
Also used : ObjectIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap) IoPrimitiveUtils.read3bLengthAndString(org.neo4j.io.fs.IoPrimitiveUtils.read3bLengthAndString) IoPrimitiveUtils.read2bLengthAndString(org.neo4j.io.fs.IoPrimitiveUtils.read2bLengthAndString)

Example 3 with ObjectIntHashMap

use of org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap in project neo4j by neo4j.

the class TokenRegistry method insertAllChecked.

private Registries insertAllChecked(List<NamedToken> tokens, Registries registries) {
    MutableObjectIntMap<String> uniquePublicNames = new ObjectIntHashMap<>();
    MutableObjectIntMap<String> uniqueInternalNames = new ObjectIntHashMap<>();
    MutableIntSet uniqueIds = new IntHashSet();
    for (NamedToken token : tokens) {
        if (token.isInternal()) {
            checkNameUniqueness(uniqueInternalNames, token, registries);
            checkNameUniqueness(registries.internalNameToId, token, registries);
            uniqueInternalNames.put(token.name(), token.id());
        } else {
            checkNameUniqueness(uniquePublicNames, token, registries);
            checkNameUniqueness(registries.publicNameToId, token, registries);
            uniquePublicNames.put(token.name(), token.id());
        }
        if (!uniqueIds.add(token.id()) || registries.idToToken.containsKey(token.id())) {
            NamedToken existingToken = registries.idToToken.get(token.id());
            throw new NonUniqueTokenException(tokenType, token, existingToken);
        }
        insertUnchecked(token, registries);
    }
    return registries;
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) ObjectIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap) NonUniqueTokenException(org.neo4j.token.api.NonUniqueTokenException) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

ObjectIntHashMap (org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap)3 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)2 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)2 NamedToken (org.neo4j.token.api.NamedToken)2 NonUniqueTokenException (org.neo4j.token.api.NonUniqueTokenException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IntPredicate (java.util.function.IntPredicate)1 IntSet (org.eclipse.collections.api.set.primitive.IntSet)1 IntIntHashMap (org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap)1 KernelException (org.neo4j.exceptions.KernelException)1 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)1 ALWAYS_TRUE_INT (org.neo4j.function.Predicates.ALWAYS_TRUE_INT)1 IoPrimitiveUtils.read2bLengthAndString (org.neo4j.io.fs.IoPrimitiveUtils.read2bLengthAndString)1 IoPrimitiveUtils.read3bLengthAndString (org.neo4j.io.fs.IoPrimitiveUtils.read3bLengthAndString)1 Status (org.neo4j.kernel.api.exceptions.Status)1