Skip to content

Commit f235aa9

Browse files
committed
Fix Mathematical Foundation section to match implementation
1 parent e5f5109 commit f235aa9

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

docs/TECHNICAL_DOCUMENTATION.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,22 @@ last.next \leftarrow H[k] & \text{otherwise}
186186
#### Set With Evicted Operation: $setWithEvicted(k, v, resetTtl = resetTtl) \rightarrow \{key: K, value: V, expiry: \mathbb{N}_0\} \cup \{\bot\}$
187187
$$\begin{align}
188188
setWithEvicted(k, v, resetTtl) &= \begin{cases}
189-
set(k, v, true, resetTtl) \land \bot & \text{if } k \in H \\
189+
update(k, v, resetTtl) \land \bot & \text{if } k \in H \\
190190
evicted \land create(k, v) & \text{if } k \notin H \land max > 0 \land size = max \\
191191
\bot \land create(k, v) & \text{if } k \notin H \land (max = 0 \lor size < max)
192192
\end{cases} \\
193+
update(k, v, resetTtl) &= H[k].value \leftarrow v \land moveToEnd(H[k]) \\
194+
& \quad \land \begin{cases}
195+
H[k].expiry \leftarrow t_{now} + ttl & \text{if } resetTtl = true \land ttl > 0 \\
196+
\text{no-op} & \text{otherwise}
197+
\end{cases} \\
193198
\text{where } evicted &= \begin{cases}
194199
\{key: this.first.key, value: this.first.value, expiry: this.first.expiry\} & \text{if } size > 0 \\
195200
\bot & \text{otherwise}
196201
\end{cases}
197202
\end{align}$$
198203

199-
**Note:** `setWithEvicted()` always calls `set()` with `bypass = true`, which means TTL is never reset during `setWithEvicted()` operations, regardless of the `resetTtl` parameter.
204+
**Note:** Unlike `set()`, `setWithEvicted()` does not use a `bypass` parameter, so TTL is reset when `resetTtl = true`.
200205

201206
**Time Complexity:** $O(1)$ amortized
202207

@@ -232,7 +237,7 @@ first \leftarrow null \land last \leftarrow null & \text{if } item.prev = null \
232237
$$\begin{align}
233238
moveToEnd(item) &= \begin{cases}
234239
\text{no-op} & \text{if } item = last \\
235-
item.prev.next \leftarrow item.next \land item.next.prev \leftarrow item.prev \land first \leftarrow item.next \land item.prev \leftarrow last \land last.next \leftarrow item \land last \leftarrow item \land first \leftarrow item \lor first & \text{if } item \neq last
240+
item.prev.next \leftarrow item.next \land item.next.prev \leftarrow item.prev \land first \leftarrow item.next \land item.prev \leftarrow last \land last.next \leftarrow item \land last \leftarrow item & \text{if } item \neq last
236241
\end{cases}
237242
\end{align}$$
238243

@@ -265,7 +270,7 @@ delete(k) & \text{if } isExpired(k) \\
265270
**TTL Reset Behavior:**
266271
- TTL is only reset during `set()` operations when `resetTtl = true` and `bypass = false`
267272
- `get()` operations never reset TTL, regardless of the `resetTtl` setting
268-
- `setWithEvicted()` operations never reset TTL because they always call `set()` with `bypass = true`
273+
- `setWithEvicted()` operations reset TTL when `resetTtl = true` (does not use bypass parameter)
269274

270275
### Space Complexity
271276

@@ -280,8 +285,8 @@ delete(k) & \text{if } isExpired(k) \\
280285
2. **List Consistency:** $first \neq null \iff last \neq null \iff size > 0$
281286
3. **Hash Consistency:** $|H| = size$
282287
4. **LRU Order:** Items in list are ordered from least to most recently used
283-
5. **TTL Validity:** $(ttl = 0 \Rightarrow \forall k \in H: H[k].expiry = 0) \land (ttl > 0 \Rightarrow \forall k \in H: H[k].expiry > t_{now})$
284-
6. **TTL Reset Invariant:** TTL is only reset during `set()` operations when `bypass = false`, never during `get()` or `setWithEvicted()` operations
288+
5. **TTL Validity:** $(ttl = 0 \Rightarrow \forall k \in H: H[k].expiry = 0) \land (ttl > 0 \Rightarrow \forall k \in H: H[k].expiry \geq t_{now})$
289+
6. **TTL Reset Invariant:** TTL is only reset during `set()` operations when `bypass = false`, and during `setWithEvicted()` operations when `resetTtl = true`
285290

286291
## TypeScript Support
287292

0 commit comments

Comments
 (0)