/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * {@inheritDoc} */ public boolean isEmpty() { return size() == 0; }
@Override public int size() { return map.size(); }
/** * Puts all key/value pairs from a given iterable into this map. */ @Override public int putAll(Iterable<? extends ObjectObjectCursor<? extends KType, ? extends VType>> iterable){ final int count = size(); for (ObjectObjectCursor<? extends KType, ? extends VType> c : iterable) { put(c.key, c.value); } return size() - count; }
/** * Return true if all keys of some other container exist in this container. * Equality comparison is performed with this object's {@link #equals(Object, Object)} * method. * Values are compared using {@link Objects#equals(Object)} method. */ protected boolean equalElements(ObjectObjectHashMap<?, ?> other) { if (other.size() != size()) { return false; } for (ObjectObjectCursor<?, ?> c : other) { KType key = (KType) c.key; if (!containsKey(key) || !java.util.Objects.equals(get(key), c.value)) { return false; } } return true; }
/** * {@inheritDoc} */ @Override public int removeAll(ObjectPredicate<? super KType> predicate) { final int before = size(); if (hasEmptyKey) { if (predicate.apply(null)) { hasEmptyKey = false; values[mask + 1] = null; } } final KType[] keys = (KType[]) this.keys; for (int slot = 0, max = this.mask; slot <= max;) { KType existing; if (!((existing = keys[slot]) == null) && predicate.apply(existing)) { // Shift, do not increment slot. shiftConflictingKeys(slot); } else { slot++; } } return before - size(); }
/** * {@inheritDoc} */ @Override public int removeAll(ObjectObjectPredicate<? super KType, ? super VType> predicate) { final int before = size(); final int mask = this.mask; if (hasEmptyKey) { if (predicate.apply(null, (VType) values[mask + 1])) { hasEmptyKey = false; values[mask + 1] = null; } } final KType[] keys = (KType[]) this.keys; final VType[] values = (VType[]) this.values; for (int slot = 0; slot <= mask;) { KType existing; if (!((existing = keys[slot]) == null) && predicate.apply(existing, values[slot])) { // Shift, do not increment slot. shiftConflictingKeys(slot); } else { slot++; } } return before - size(); }
@Override protected boolean equalElements(ObjectObjectHashMap<?, ?> other) { if (other.size() != size()) { return false; } Iterator<? extends ObjectObjectCursor<?, ?>> i = other.iterator(); while (i.hasNext()) { ObjectObjectCursor<?, ?> c = i.next(); KType key = (KType) c.key; if (!containsKey(key) || !equals(get(key), c.value)) { // Compare values using the same function as keys. return false; } } return true; } /* */
/** * This method is invoked when there is a new key/ value pair to be inserted into * the buffers but there is not enough empty slots to do so. * * New buffers are allocated. If this succeeds, we know we can proceed * with rehashing so we assign the pending element to the previous buffer * (possibly violating the invariant of having at least one empty slot) * and rehash all keys, substituting new buffers at the end. */ protected void allocateThenInsertThenRehash(int slot, KType pendingKey, VType pendingValue) { assert assigned == resizeAt && (((KType) keys[slot]) == null) && !((pendingKey) == null); // Try to allocate new buffers first. If we OOM, we leave in a consistent state. final KType[] prevKeys = (KType[]) this.keys; final VType[] prevValues = (VType[]) this.values; allocateBuffers(nextBufferSize(mask + 1, size(), loadFactor)); assert this.keys.length > prevKeys.length; // We have succeeded at allocating new data so insert the pending key/value at // the free slot in the old arrays before rehashing. prevKeys[slot] = pendingKey; prevValues[slot] = pendingValue; // Rehash old keys, including the pending key. rehash(prevKeys, prevValues); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
public static void writeFieldStats(StreamOutput out, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException { out.writeVInt(fieldStatistics.size()); for (ObjectObjectCursor<String, CollectionStatistics> c : fieldStatistics) { out.writeString(c.key); CollectionStatistics statistics = c.value; assert statistics.maxDoc() >= 0; out.writeVLong(statistics.maxDoc()); out.writeVLong(addOne(statistics.docCount())); out.writeVLong(addOne(statistics.sumTotalTermFreq())); out.writeVLong(addOne(statistics.sumDocFreq())); } }
@Override public void writeTo(final StreamOutput out) throws IOException { out.writeVInt(termStatistics.size()); for (ObjectObjectCursor<Term, TermStatistics> c : termStatistics()) { Term term = c.key; out.writeString(term.field()); out.writeBytesRef(term.bytes()); TermStatistics stats = c.value; out.writeBytesRef(stats.term()); out.writeVLong(stats.docFreq()); out.writeVLong(DfsSearchResult.addOne(stats.totalTermFreq())); } DfsSearchResult.writeFieldStats(out, fieldStatistics); out.writeVLong(maxDoc); } }
indexCount = countsPerIndex.size(); for (ObjectObjectCursor<String, ShardStats> indexCountsCursor : countsPerIndex) { shards.addIndexShardCount(indexCountsCursor.value);
public static void writeFieldStats(StreamOutput out, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException { out.writeVInt(fieldStatistics.size()); for (ObjectObjectCursor<String, CollectionStatistics> c : fieldStatistics) { out.writeString(c.key); CollectionStatistics statistics = c.value; assert statistics.maxDoc() >= 0; out.writeVLong(statistics.maxDoc()); out.writeVLong(addOne(statistics.docCount())); out.writeVLong(addOne(statistics.sumTotalTermFreq())); out.writeVLong(addOne(statistics.sumDocFreq())); } }
public static void writeFieldStats(StreamOutput out, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException { out.writeVInt(fieldStatistics.size()); for (ObjectObjectCursor<String, CollectionStatistics> c : fieldStatistics) { out.writeString(c.key); CollectionStatistics statistics = c.value; assert statistics.maxDoc() >= 0; out.writeVLong(statistics.maxDoc()); out.writeVLong(addOne(statistics.docCount())); out.writeVLong(addOne(statistics.sumTotalTermFreq())); out.writeVLong(addOne(statistics.sumDocFreq())); } }
public static void writeFieldStats(StreamOutput out, ObjectObjectHashMap<String, CollectionStatistics> fieldStatistics) throws IOException { out.writeVInt(fieldStatistics.size()); for (ObjectObjectCursor<String, CollectionStatistics> c : fieldStatistics) { out.writeString(c.key); CollectionStatistics statistics = c.value; assert statistics.maxDoc() >= 0; out.writeVLong(statistics.maxDoc()); out.writeVLong(addOne(statistics.docCount())); out.writeVLong(addOne(statistics.sumTotalTermFreq())); out.writeVLong(addOne(statistics.sumDocFreq())); } }