public String findKey(byte[] obj) { if (nodeKeySlots.size() == 0) { return null; } long objHash = hashFn.hashBytes(obj).asLong(); Long2ObjectSortedMap<String> subMap = nodeKeySlots.tailMap(objHash); if (subMap.isEmpty()) { return nodeKeySlots.long2ObjectEntrySet().first().getValue(); } Long2ObjectMap.Entry<String> firstEntry = subMap.long2ObjectEntrySet().first(); return firstEntry.getValue(); }
private void evict() { Node victim = null; for (Node head : headQ) { if (head.next != head) { victim = head.next; break; } } if (victim == null) { return; } victim.remove(); data.remove(victim.key); out.put(victim.key, victim); if (out.size() > maxOut) { out.remove(out.firstLongKey()); } }
public Selection lessThan(long value) { Selection selection = new BitmapBackedSelection(); Long2ObjectSortedMap<IntArrayList> head = index.headMap(value); // we add 1 to get values equal to the arg for (IntArrayList keys : head.values()) { addAllToSelection(keys, selection); } return selection; }
/** * Returns an iterable yielding a bidirectional iterator that will be * {@linkplain FastSortedEntrySet fast}, if possible, on the * {@linkplain Map#entrySet() entry set} of the provided {@code map}. * * @param map * a map from which we will try to extract an iterable yielding a * (fast) bidirectional iterator on the entry set. * @return an iterable yielding a bidirectional iterator on the entry set of the * given map that will be fast, if possible. * @since 8.0.0 */ @SuppressWarnings("unchecked") public static <V> ObjectBidirectionalIterable<Long2ObjectMap.Entry<V>> fastIterable(Long2ObjectSortedMap<V> map) { final ObjectSortedSet<Long2ObjectMap.Entry<V>> entries = map.long2ObjectEntrySet(); return entries instanceof Long2ObjectSortedMap.FastSortedEntrySet ? ((Long2ObjectSortedMap.FastSortedEntrySet<V>) entries)::fastIterator : entries; } /**
public void removeExcess() { int currentSize = keyToValue.size(); while (currentSize > flushedSize) { long firstKey = timeStampToKey.firstLongKey(); Set<KEY> keys = timeStampToKey.get(firstKey); Iterator<KEY> keyIterator = keys.iterator(); while (keyIterator.hasNext() && currentSize > flushedSize) { KEY key = keyIterator.next(); VALUE value = keyToValue.remove(key); if (value == null) { continue; } currentSize--; changed.remove(key); keyToTimeStamp.remove(key); flushListener.flush(key, value); } if (keys.isEmpty()) { timeStampToKey.remove(firstKey); } } }
public VALUE put(long timeStamp, KEY key, VALUE value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); changed.add(key); Long oldTimeStamp = keyToTimeStamp.put(key, timeStamp); if (oldTimeStamp == null || oldTimeStamp != timeStamp) { Set<KEY> keys = timeStampToKey.get(timeStamp); if (keys == null) { keys = Sets.newHashSet(); timeStampToKey.put(timeStamp, keys); } keys.add(key); } if (oldTimeStamp != null) { timeStampToKey.get(oldTimeStamp).remove(key); } return keyToValue.put(key, value); }
/** * Returns a copy of this consistent hash function. * * <p>Note that for this method to work properly, the skip strategy {@linkplain #ConsistentHashFunction(SkipStrategy) provided * at construction time}, if any, must be stateless, as it will be shared by the copy. * * @return a copy of this consistent hash function. */ @SuppressWarnings("unchecked") public ConsistentHashFunction<T> copy() { final Long2ObjectSortedMap<Object> replicaeCopy = new Long2ObjectAVLTreeMap<Object>(); for( Long2ObjectMap.Entry<Object> entry: replicae.long2ObjectEntrySet() ) { final Object value = entry.getValue(); replicaeCopy.put( entry.getLongKey(), value instanceof ObjectAVLTreeSet ? ((ObjectAVLTreeSet<T>)value).clone() : value ); } return new ConsistentHashFunction<T>( replicaeCopy, new Object2IntOpenHashMap<T>( sizes ), skipStrategy ); }
/** * Removes a bucket. * * @param bucket the bucket to be removed. * @return false if the bucket was not present. */ @SuppressWarnings("unchecked") public boolean remove( final T bucket ) { if ( !sizes.containsKey( bucket ) ) return false; final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator( bucket.hashCode() ); final int size = sizes.removeInt( bucket ); for ( int i = 0; i < size * REPLICAE_PER_BUCKET; i++ ) { final long point = random.nextLong(); final Object o = replicae.remove( point ); if ( o instanceof ObjectAVLTreeSet ) { if ( DEBUG ) System.err.println( "Removing from " + point + " conflict set..." ); final ObjectAVLTreeSet<T> conflictSet = (ObjectAVLTreeSet<T>)o; conflictSet.remove( bucket ); if ( conflictSet.size() > 1 ) replicae.put( point, conflictSet ); else replicae.put( point, conflictSet.first() ); } else if ( o != null && ( (T)o ).compareTo( bucket ) != 0 ) replicae.put( point, o ); } return true; }
@Override public void reset(long term) { keys = map.tailMap(term).long2ObjectEntrySet().iterator(); }
writeVLong(terms.size(), out); long lastTerm = 0; for (final Long2ObjectMap.Entry<IntArrayList> e : terms.long2ObjectEntrySet()) { final long term = e.getLongKey(); final IntList docList = e.getValue();
@Override public void close() throws IOException { if (currentDocList != null && currentDocList.size() > 0) terms.put(term, currentDocList); intFields.put(field, terms); memoryUsageEstimate += usage(field, terms); } };
@Override public long firstLongKey() { return sortedMap.firstLongKey(); } @Override
@Override public void record(long key) { policyStats.recordOperation(); Node node = data.get(key); if (node == null) { policyStats.recordMiss(); node = out.remove(key); if (node == null) { node = new Node(key); } data.put(key, node); if (data.size() > maximumSize) { policyStats.recordEviction(); evict(); } } else { policyStats.recordHit(); node.remove(); } node.reference++; node.queueIndex = queueIndexFor(node); node.appendToTail(headQ[node.queueIndex]); node.expireTime = currentTime + lifetime; adjust(); }
/** * {@inheritDoc} * <p> * Note that this specification strengthens the one given in * {@link SortedMap#tailMap(Object)}. * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Long2ObjectSortedMap<V> tailMap(final Long from) { return tailMap((from).longValue()); } /**
@Override public LongComparator comparator() { return sortedMap.comparator(); } @Override
public VALUE remove(KEY key) { Preconditions.checkNotNull(key); Long timeStamp = keyToTimeStamp.get(key); if (timeStamp != null) { keyToTimeStamp.remove(key); Set<KEY> keys = timeStampToKey.get(timeStamp); keys.remove(key); } changed.remove(key); return keyToValue.remove(key); }
/** * Returns a sorted-set view of the mappings contained in this map. * <p> * Note that this specification strengthens the one given in the corresponding * type-specific unsorted map. * * @return a sorted-set view of the mappings contained in this map. * @see SortedMap#entrySet() * @deprecated Please use the corresponding type-specific method instead. */ @SuppressWarnings({"unchecked", "rawtypes"}) @Deprecated @Override default ObjectSortedSet<Map.Entry<Long, V>> entrySet() { return (ObjectSortedSet) long2ObjectEntrySet(); } /**
if ( ( o = replicae.get( point ) ) != null ) { if ( o != bucket ) { // o == bucket should happen with very low probability. if ( o instanceof ObjectAVLTreeSet ) ( (ObjectAVLTreeSet<T>)o ).add( bucket ); conflictSet.add( (T)o ); conflictSet.add( bucket ); replicae.put( point, conflictSet ); else replicae.put( point, bucket );
@Override public void nextTerm(long term) throws IOException { if (currentDocList != null && currentDocList.size() > 0) terms.put(this.term, currentDocList); this.term = term; currentDocList = new IntArrayList(); }
@Override public long firstLongKey() { synchronized (sync) { return sortedMap.firstLongKey(); } } @Override