/** * @return a new list of all keys (makes a copy) */ public Set<LongPair> items() { Set<LongPair> items = new HashSet<>(this.size); forEach((item1, item2) -> items.add(new LongPair(item1, item2))); return items; }
/** * it is not a thread-safe method and it should be called before acquiring a lock by a caller. * * @param index * @return */ private LongPair removeAtWithoutLock(int index) { if (this.size > 0) { LongPair item = new LongPair(data[index], data[index + 1]); data[index] = EmptyItem; data[index + 1] = EmptyItem; --this.size; int lastIndex = this.size << 1; swap(index, lastIndex); minHeapify(index, lastIndex - 2); return item; } else { return null; } }
public synchronized LongPair peek() { if (this.size > 0) { return new LongPair(data[0], data[1]); } else { return null; } }
/** * @return a new list of keys with max provided numberOfItems (makes a copy) */ public Set<LongPair> items(int numberOfItems) { Set<LongPair> items = new HashSet<>(this.size); forEach((item1, item2) -> { if (items.size() < numberOfItems) { items.add(new LongPair(item1, item2)); } }); return items; }
/** * @return a new list of all keys (makes a copy) */ public Set<LongPair> items() { Set<LongPair> items = new HashSet<>(this.size); forEach((item1, item2) -> items.add(new LongPair(item1, item2))); return items; }
/** * it is not a thread-safe method and it should be called before acquiring a lock by a caller. * * @param index * @return */ private LongPair removeAtWithoutLock(int index) { if (this.size > 0) { LongPair item = new LongPair(data[index], data[index + 1]); data[index] = EmptyItem; data[index + 1] = EmptyItem; --this.size; int lastIndex = this.size << 1; swap(index, lastIndex); minHeapify(index, lastIndex - 2); return item; } else { return null; } }
public synchronized LongPair peek() { if (this.size > 0) { return new LongPair(data[0], data[1]); } else { return null; } }
/** * @return a new list of keys with max provided numberOfItems (makes a copy) */ public Set<LongPair> items(int numberOfItems) { Set<LongPair> items = new HashSet<>(this.size); forEach((item1, item2) -> { if (items.size() < numberOfItems) { items.add(new LongPair(item1, item2)); } }); return items; }