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;
}
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;
}
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;
}
Aggregations