aboutsummaryrefslogtreecommitdiff
path: root/internal/mru/sync.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-07 19:12:42 +0000
committerGravatar Runxi Yu2026-06-07 19:14:20 +0000
commit7944920f2cb0e5470d0bbe7e76ced3c6a7197bb5 (patch)
treed914d86b26a475e6b00f72902c4e9f8fc05c68f2 /internal/mru/sync.go
parentobject/store: Add CoordinatedQuarantine (diff)
internal/mru: Add
Diffstat (limited to 'internal/mru/sync.go')
-rw-r--r--internal/mru/sync.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/mru/sync.go b/internal/mru/sync.go
new file mode 100644
index 00000000..69fc3446
--- /dev/null
+++ b/internal/mru/sync.go
@@ -0,0 +1,31 @@
+package mru
+
+// Sync reconciles the order's membership to present.
+//
+// Surviving keys keep their relative recency order,
+// absent keys are dropped,
+// and newly present keys are appended after the survivors.
+func (order *Order[K]) Sync(present map[K]struct{}) {
+ order.mu.Lock()
+ defer order.mu.Unlock()
+
+ keys := order.Keys()
+
+ next := make([]K, 0, len(present))
+ seen := make(map[K]struct{}, len(present))
+
+ for _, key := range keys {
+ if _, ok := present[key]; ok {
+ next = append(next, key)
+ seen[key] = struct{}{}
+ }
+ }
+
+ for key := range present {
+ if _, ok := seen[key]; !ok {
+ next = append(next, key)
+ }
+ }
+
+ order.snapshot.Store(&next)
+}