LinkedDictionary: mode-aware ordering — pure reads in Dynamic, fail-fast LRU in Fixed - #16
LinkedDictionary: mode-aware ordering — pure reads in Dynamic, fail-fast LRU in Fixed#16Codeturion wants to merge 3 commits into
Conversation
…rder with pure reads, Fixed reorders on access and fail-fasts enumerators
There was a problem hiding this comment.
Code Review
This pull request introduces a CapacityMode to LinkedDictionary, separating its behavior into Dynamic (preserving insertion order with pure reads) and Fixed (acting as an LRU cache). The implementation of AddOrUpdate and TryGetValue has been updated to only reorder elements when in Fixed mode, and several new tests have been added to verify these behaviors. The review feedback correctly identifies that the newly added tests assert the incorrect enumeration order (expecting insertion order instead of reverse insertion order/newest-to-oldest), which will cause test failures, and provides code suggestions to fix these assertions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…, LRU->MRU in Fixed (LinkedHashMap semantics)
|
Follow-up in 130e051: the enumerator walked head→tail, which is MRU-first (reverse insertion) — the old "insertion order" test even asserted |
|
The three gemini-code-assist comments describe the pre-130e051 behavior. That commit changed the enumerator to walk tail→head, so enumeration is now oldest-first (insertion order in Dynamic mode, LRU→MRU in Fixed mode) and |
Addresses external feedback that
LinkedDictionarymutates its ordering chain on every lookup.Problem
TryGetValue/this[key]get calledMoveToFronton every hit — every read was a write, contradicting the doc claim of preserved insertion order.MoveToFrontdid not bump_version, so lookups duringforeachsilently corrupted iteration (skipped/repeated items) instead of throwing.ContainsKeydidn't reorder whileTryGetValuedid — inconsistent read semantics.Dynamicmode (no eviction) the reorder-on-read was pure overhead.Change
TryGetValue/indexer get;AddOrUpdateon an existing key keeps its insertion position. Iteration order is true insertion order._versionso an active enumerator fails fast instead of silently corrupting.Fixedmode; 4 new tests covering Dynamic purity, insertion-position stability, safe lookups during Dynamic enumeration, and Fixed-mode fail-fast.Breaking
Behavioral change for anyone relying on LRU reordering in
Dynamicmode — that usage now belongs inFixedmode.ConcurrentLinkedDictionary(timestamp-based) andBoundedDictionaryare unaffected;LinkedMultiMapstill reorders on read but documents it (possible follow-up).