private void TrimItems() { while (_lastFreqForItem.Count > TopKMax) { if (Topk.Count == 0) { break; } var last = Topk.LastOrDefault(); if (last.Value is Deque <ByteBuffer> deque) { var valueRemoved = deque.RemoveLast(); _lastFreqForItem.Remove(valueRemoved); if (deque.IsEmpty()) { Topk.Remove(last.Key); } } else { Topk.Remove(last.Key); _lastFreqForItem.Remove((ByteBuffer)last.Value); } } }
private void RemoveItemFromSorted( long frequency, ByteBuffer value) { var existing = Topk.Get(frequency); if (existing is Deque <ByteBuffer> deque) { deque.Remove(value); if (deque.IsEmpty()) { Topk.Remove(frequency); } } else if (existing != null) { Topk.Remove(frequency); } }