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); } }
private void AddItemToSorted( long frequency, ByteBuffer value) { var existing = Topk.Get(frequency); if (existing == null) { Topk.Put(frequency, value); } else if (existing is Deque <ByteBuffer> existingDeque) { existingDeque.Add(value); } else { Deque <ByteBuffer> deque = new ArrayDeque <ByteBuffer>(2); deque.Add((ByteBuffer)existing); deque.Add(value); Topk.Put(frequency, deque); } }