Skip to content

Commit abcf9b7

Browse files
committed
docs(cache): correct remove() complexity comment
The previous comment claimed O(1) location lookup; in practice the dnIndex only confirms presence, then a linear scan over c.items finds the matching slice element by pointer comparison, and buildIndexes() rebuilds every index. Overall removal is O(n). Addresses review feedback on #579. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
1 parent cea1767 commit abcf9b7

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

internal/ldap_cache/cache.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ func (c *Cache[T]) update(fn func(*T)) {
138138
// without waiting for the next background Refresh (which can be delayed
139139
// by AD replication between the modifying DC and the readonly-bind DC).
140140
//
141-
// Uses the dnIndex for O(1) location lookup and slices.Delete for the
142-
// slice shrink (which zeroes the vacated slot, so pointer fields inside
143-
// T do not keep the removed entry's data alive indefinitely).
141+
// The dnIndex provides fast presence detection, but locating the
142+
// matching slice element still requires a linear scan over c.items
143+
// (we compare slice-element pointers, not by DN). After deletion we
144+
// rebuild every index, which is also O(n). Overall removal is O(n).
145+
// slices.Delete shrinks the slice and zeroes the vacated slot, so
146+
// pointer fields inside T do not keep the removed entry's data alive
147+
// indefinitely.
144148
func (c *Cache[T]) remove(dn string) {
145149
c.m.Lock()
146150
defer c.m.Unlock()

0 commit comments

Comments
 (0)