Skip to content

Commit cce385b

Browse files
authored
fix(docs): correct misleading set() LRU ordering explanation in explanation/index.md (#54)
The previous snippet implied that `OrderedDict.__setitem__` alone moves existing keys to the end, which is incorrect. Added `move_to_end()` call and updated the surrounding text to clarify that explicit reordering is required for existing keys. Closes #48. Made-with: Cursor
1 parent 6bd36f4 commit cce385b

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

docs/explanation/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ When an item is accessed via `get()`, it's moved to the end of the `OrderedDict`
5555
self._data.move_to_end(key)
5656
```
5757

58-
When an item is stored via `set()`, it's added to the end (or moved to the end if it already exists):
58+
When an item is stored via `set()`, it's added to the end if new. For existing keys, an explicit `move_to_end()` call is required, since `OrderedDict.__setitem__` does **not** reorder existing keys:
5959

6060
```python
61-
self._data[key] = value_obj # Adds to end if new, or updates existing
61+
self._data[key] = value_obj # Adds to end if new, does NOT move if existing
62+
self._data.move_to_end(key) # Explicitly moves existing key to end
6263
```
6364

6465
This ensures that frequently accessed items naturally migrate toward the end, while rarely accessed items accumulate at the beginning.

0 commit comments

Comments
 (0)