From 08556257cc462c9dc675609c7f90080cfa4dacff Mon Sep 17 00:00:00 2001 From: Lisandro Pin Date: Thu, 5 Jun 2025 16:11:36 +0200 Subject: [PATCH] Add a small comment description for `CompactMap()`. --- weed/storage/needle_map/compact_map.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weed/storage/needle_map/compact_map.go b/weed/storage/needle_map/compact_map.go index d6c9fe296..33514476a 100644 --- a/weed/storage/needle_map/compact_map.go +++ b/weed/storage/needle_map/compact_map.go @@ -1,5 +1,15 @@ package needle_map +/* CompactMap is an in-memory map of needle indeces, optimized for memory usage. + * + * It's implemented as a map of sorted indeces segments, which are in turn accessed through binary + * search. This guarantees a best-case scenario (ordered inserts/updates) of O(N) and a worst case + * scenario of O(log n) runtime, with memory usage unaffected by insert ordering. + * + * Note that even at O(log n), the clock time for both reads and writes is very low, so CompactMap + * will seldom bottleneck index operations. + */ + import ( "fmt" "math"