@Override public boolean put(K key, V value) { SpillableSetImpl<V> spillableSet = getHelper(key); if (spillableSet == null) { if (timeExtractor == null) { spillableSet = new SpillableSetImpl<>( bucket, keyValueSerdeManager.serializeDataKey(key, true).toByteArray(), store, valueSerde); } else { spillableSet = new SpillableSetImpl<>( keyValueSerdeManager.serializeDataKey(key, true).toByteArray(), store, valueSerde, new FixedTimeExtractor(timeExtractor.getTime(key))); } spillableSet.setup(context); cache.put(key, spillableSet); } return spillableSet.add(value); }
private SpillableSetImpl<V> getHelper(@NotNull K key) { SpillableSetImpl<V> spillableSet = cache.get(key); if (spillableSet == null) { long keyTime = -1; Pair<Integer, V> meta; if (timeExtractor != null) { keyTime = timeExtractor.getTime(key); } meta = map.get(key); if (meta == null) { return null; } Slice keyPrefix = keyValueSerdeManager.serializeDataKey(key, false); if (timeExtractor != null) { spillableSet = new SpillableSetImpl<>( keyPrefix.toByteArray(), store, valueSerde, new FixedTimeExtractor(keyTime)); } else { spillableSet = new SpillableSetImpl<>(bucket, keyPrefix.toByteArray(), store, valueSerde); } spillableSet.setSize(meta.getLeft()); spillableSet.setHead(meta.getRight()); spillableSet.setup(context); } cache.put(key, spillableSet); return spillableSet; }