/** * If <code>key</code> exists, <code>putValue</code> is inserted into the map, * otherwise any existing value is incremented by <code>additionValue</code>. * * @param key * The key of the value to adjust. * @param putValue * The value to put if <code>key</code> does not exist. * @param incrementValue * The value to add to the existing value if <code>key</code> exists. * @return Returns the current value associated with <code>key</code> (after * changes). */ @SuppressWarnings("cast") @Override public int putOrAdd(final KType key, int putValue, final int incrementValue) { if (containsKey(key)) { putValue = get(key); putValue = (int) (((putValue) + (incrementValue))); } put(key, putValue); return putValue; }
/** * Creates a hash map from two index-aligned arrays of key-value pairs. Default load factor is used. */ public static <KType> ObjectIntHashMap<KType> from(final KType[] keys, final int[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } final ObjectIntHashMap<KType> map = new ObjectIntHashMap<KType>(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; }
/** * {@inheritDoc} */ @Override public boolean putIfAbsent(final KType key, final int value) { if (!containsKey(key)) { put(key, value); return true; } return false; }
/** * {@inheritDoc} */ @Override public ObjectIntHashMap<KType> clone() { //clone to size() to prevent some cases of exponential sizes, final ObjectIntHashMap<KType> cloned = new ObjectIntHashMap<KType>(this.size(), this.loadFactor); //We must NOT clone because of independent perturbations seeds cloned.putAll(this); return cloned; }
static ObjectIntHashMap<IRI> initMap() { ObjectIntHashMap<IRI> predicates = new ObjectIntHashMap<>(); AtomicInteger nextId = new AtomicInteger(1); List<OWLRDFVocabulary> ORDERED_URIS = Arrays.asList(RDF_TYPE, RDFS_LABEL, OWL_DEPRECATED, RDFS_COMMENT, RDFS_IS_DEFINED_BY, RDF_FIRST, RDF_REST, OWL_EQUIVALENT_CLASS, OWL_EQUIVALENT_PROPERTY, RDFS_SUBCLASS_OF, RDFS_SUB_PROPERTY_OF, RDFS_DOMAIN, RDFS_RANGE, OWL_DISJOINT_WITH, OWL_ON_PROPERTY, OWL_DATA_RANGE, OWL_ON_CLASS, OWL_ANNOTATED_SOURCE, OWL_ANNOTATED_PROPERTY, OWL_ANNOTATED_TARGET); ORDERED_URIS.forEach(iri -> predicates.put(iri.getIRI(), nextId.getAndIncrement())); Stream.of(OWLRDFVocabulary.values()) .forEach(iri -> predicates.putIfAbsent(iri.getIRI(), nextId.getAndIncrement())); return predicates; }
private static int comparePredicates(RDFResourceIRI predicate, RDFResourceIRI otherPredicate) { IRI predicateIRI = predicate.getIRI(); int specialPredicateRank = specialPredicateRanks.get(predicateIRI); IRI otherPredicateIRI = otherPredicate.getIRI(); int otherSpecialPredicateRank = specialPredicateRanks.get(otherPredicateIRI); if (specialPredicateRank != specialPredicateRanks.getDefaultValue()) { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return Integer.compare(specialPredicateRank, otherSpecialPredicateRank); } else { return -1; } } else { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return +1; } else { return predicateIRI.compareTo(otherPredicateIRI); } } }
@Override public Set<OWLAxiom> getPrincipalIdeal(Atom atom) { return asSet(getAtomModule(atomIndex.get(atom))); }
/** * @param axioms axioms * @param type type */ public AtomicDecompositionImpl(List<OWLAxiom> axioms, ModuleType type) { this.type = type; decomposer = new Decomposer(AxiomSelector.wrap(axioms), new SyntacticLocalityChecker()); int size = decomposer.getAOS(this.type).size(); atoms = new ArrayList<>(); for (int i = 0; i < size; i++) { final Atom atom = new Atom(asSet(decomposer.getAOS().get(i).getAtomAxioms())); atoms.add(atom); atomIndex.put(atom, i); for (OWLEntity e : atom.getSignature()) { termBasedIndex.put(e, atom); } } for (int i = 0; i < size; i++) { Set<OntologyAtom> dependentIndexes = decomposer.getAOS().get(i).getDependencies(); for (OntologyAtom j : dependentIndexes) { dependencies.put(atoms.get(i), atoms.get(j.getId())); dependents.put(atoms.get(j.getId()), atoms.get(i)); } } }
if (other.size() != this.size()) { return false; final EntryIterator it = this.iterator(); if (!other.containsKey(c.key)) { final int otherValue = other.get(c.key);
/** * Create a new hash map without providing the full generic signature * (constructor shortcut). */ public static <KType> ObjectIntHashMap<KType> newInstance() { return new ObjectIntHashMap<KType>(); }
final int[] oldValues = ((this.values)); allocateBuffers(HashContainers.nextBufferSize(this.keys.length, this.assigned, this.loadFactor)); slot = (BitMixer.mix(hashKey((key)) , (perturb))) & mask; existing_distance = probe_distance(slot, cached);
/** * Creates a hash map with the given initial capacity, * load factor. * * @param loadFactor The load factor (greater than zero and smaller than 1). */ public ObjectIntHashMap(final int initialCapacity, final double loadFactor) { this.loadFactor = loadFactor; //take into account of the load factor to guarantee no reallocations before reaching initialCapacity. allocateBuffers(HashContainers.minBufferSize(initialCapacity, loadFactor)); }
static ObjectIntHashMap<IRI> initMap() { ObjectIntHashMap<IRI> predicates = new ObjectIntHashMap<>(); AtomicInteger nextId = new AtomicInteger(1); List<OWLRDFVocabulary> ORDERED_URIS = Arrays.asList(RDF_TYPE, RDFS_LABEL, OWL_DEPRECATED, RDFS_COMMENT, RDFS_IS_DEFINED_BY, RDF_FIRST, RDF_REST, OWL_EQUIVALENT_CLASS, OWL_EQUIVALENT_PROPERTY, RDFS_SUBCLASS_OF, RDFS_SUB_PROPERTY_OF, RDFS_DOMAIN, RDFS_RANGE, OWL_DISJOINT_WITH, OWL_ON_PROPERTY, OWL_DATA_RANGE, OWL_ON_CLASS, OWL_ANNOTATED_SOURCE, OWL_ANNOTATED_PROPERTY, OWL_ANNOTATED_TARGET); ORDERED_URIS.forEach(iri -> predicates.put(iri.getIRI(), nextId.getAndIncrement())); Stream.of(OWLRDFVocabulary.values()) .forEach(iri -> predicates.putIfAbsent(iri.getIRI(), nextId.getAndIncrement())); return predicates; }
private static int comparePredicates(RDFResourceIRI predicate, RDFResourceIRI otherPredicate) { IRI predicateIRI = predicate.getIRI(); int specialPredicateRank = specialPredicateRanks.get(predicateIRI); IRI otherPredicateIRI = otherPredicate.getIRI(); int otherSpecialPredicateRank = specialPredicateRanks.get(otherPredicateIRI); if (specialPredicateRank != specialPredicateRanks.getDefaultValue()) { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return Integer.compare(specialPredicateRank, otherSpecialPredicateRank); } else { return -1; } } else { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return +1; } else { return predicateIRI.compareTo(otherPredicateIRI); } } }
@Override public Set<OWLAxiom> getPrincipalIdeal(Atom atom) { return asSet(getAtomModule(atomIndex.get(atom))); }
/** * @param axioms axioms * @param type type */ public AtomicDecompositionImpl(List<OWLAxiom> axioms, ModuleType type) { this.type = type; decomposer = new Decomposer(AxiomSelector.wrap(axioms), new SyntacticLocalityChecker()); int size = decomposer.getAOS(this.type).size(); atoms = new ArrayList<>(); for (int i = 0; i < size; i++) { final Atom atom = new Atom(asSet(decomposer.getAOS().get(i).getAtomAxioms())); atoms.add(atom); atomIndex.put(atom, i); for (OWLEntity e : atom.getSignature()) { termBasedIndex.put(e, atom); } } for (int i = 0; i < size; i++) { Set<OntologyAtom> dependentIndexes = decomposer.getAOS().get(i).getDependencies(); for (OntologyAtom j : dependentIndexes) { dependencies.put(atoms.get(i), atoms.get(j.getId())); dependents.put(atoms.get(j.getId()), atoms.get(i)); } } }
/** * Create a hash map from another associative container. (constructor shortcut) Default load factor is used. */ public static <KType> ObjectIntHashMap<KType> from( final ObjectIntAssociativeContainer<KType> container) { return new ObjectIntHashMap<KType>(container); }
static ObjectIntHashMap<IRI> initMap() { ObjectIntHashMap<IRI> predicates = new ObjectIntHashMap<>(); AtomicInteger nextId = new AtomicInteger(1); List<OWLRDFVocabulary> ORDERED_URIS = Arrays.asList(RDF_TYPE, RDFS_LABEL, OWL_DEPRECATED, RDFS_COMMENT, RDFS_IS_DEFINED_BY, RDF_FIRST, RDF_REST, OWL_EQUIVALENT_CLASS, OWL_EQUIVALENT_PROPERTY, RDFS_SUBCLASS_OF, RDFS_SUB_PROPERTY_OF, RDFS_DOMAIN, RDFS_RANGE, OWL_DISJOINT_WITH, OWL_ON_PROPERTY, OWL_DATA_RANGE, OWL_ON_CLASS, OWL_ANNOTATED_SOURCE, OWL_ANNOTATED_PROPERTY, OWL_ANNOTATED_TARGET); ORDERED_URIS.forEach(iri -> predicates.put(iri.getIRI(), nextId.getAndIncrement())); Stream.of(OWLRDFVocabulary.values()) .forEach(iri -> predicates.putIfAbsent(iri.getIRI(), nextId.getAndIncrement())); return predicates; }
private static int comparePredicates(RDFResourceIRI predicate, RDFResourceIRI otherPredicate) { IRI predicateIRI = predicate.getIRI(); int specialPredicateRank = specialPredicateRanks.get(predicateIRI); IRI otherPredicateIRI = otherPredicate.getIRI(); int otherSpecialPredicateRank = specialPredicateRanks.get(otherPredicateIRI); if (specialPredicateRank != specialPredicateRanks.getDefaultValue()) { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return Integer.compare(specialPredicateRank, otherSpecialPredicateRank); } else { return -1; } } else { if (otherSpecialPredicateRank != specialPredicateRanks.getDefaultValue()) { return +1; } else { return predicateIRI.compareTo(otherPredicateIRI); } } }