@@ -159,17 +159,17 @@ The LRU cache maintains a doubly-linked list $L$ and a hash table $H$ for O(1) o
159159
160160** Note:** The mathematical notation uses ` create(k, v) ` to represent the item creation logic that is inline in the actual implementation.
161161
162- #### Set Operation: $set(k, v, bypass = false, resetTtl = resetTtl ) \rightarrow \text{LRU}$
162+ #### Set Operation: $set(k, v) \rightarrow \text{LRU}$
163163
164164$$
165165\begin{align}
166- set(k, v, bypass, resetTtl ) &= \begin{cases}
167- update(k, v, bypass, resetTtl ) & \text{if } k \in H \\
166+ set(k, v) &= \begin{cases}
167+ update(k, v) & \text{if } k \in H \\
168168insert(k, v) & \text{if } k \notin H
169169\end{cases} \\
170- update(k, v, bypass, resetTtl ) &= H[k].value \leftarrow v \land moveToEnd(H[k]) \\
170+ update(k, v) &= H[k].value \leftarrow v \land moveToEnd(H[k]) \\
171171& \quad \land \begin{cases}
172- H[k].expiry \leftarrow t_{now} + ttl & \text{if } bypass = false \land resetTtl = true \land ttl > 0 \\
172+ H[k].expiry \leftarrow t_{now} + ttl & \text{if } resetTtl = true \land ttl > 0 \\
173173\text{no-op} & \text{otherwise}
174174\end{cases} \\
175175insert(k, v) &= \begin{cases}
187187
188188** Time Complexity:** $O(1)$ amortized
189189
190- #### Set With Evicted Operation: $setWithEvicted(k, v, resetTtl = resetTtl ) \rightarrow \{ key: K, value: V, expiry: \mathbb{N}_ 0\} \cup \{ \bot\} $
190+ #### Set With Evicted Operation: $setWithEvicted(k, v) \rightarrow \{ key: K, value: V, expiry: \mathbb{N}_ 0\} \cup \{ \bot\} $
191191
192192$$
193193\begin{align}
194- setWithEvicted(k, v, resetTtl ) &= \begin{cases}
195- update(k, v, resetTtl ) \land \bot & \text{if } k \in H \\
194+ setWithEvicted(k, v) &= \begin{cases}
195+ update(k, v) \land \bot & \text{if } k \in H \\
196196evicted \land create(k, v) & \text{if } k \notin H \land max > 0 \land size = max \\
197197\bot \land create(k, v) & \text{if } k \notin H \land (max = 0 \lor size < max)
198198\end{cases} \\
199- update(k, v, resetTtl ) &= H[k].value \leftarrow v \land moveToEnd(H[k]) \\
199+ update(k, v) &= H[k].value \leftarrow v \land moveToEnd(H[k]) \\
200200& \quad \land \begin{cases}
201201H[k].expiry \leftarrow t_{now} + ttl & \text{if } resetTtl = true \land ttl > 0 \\
202202\text{no-op} & \text{otherwise}
@@ -208,8 +208,6 @@ H[k].expiry \leftarrow t_{now} + ttl & \text{if } resetTtl = true \land ttl > 0
208208\end{align}
209209$$
210210
211- ** Note:** Unlike ` set() ` , ` setWithEvicted() ` does not use a ` bypass ` parameter, so TTL is reset when ` resetTtl = true ` .
212-
213211** Time Complexity:** $O(1)$ amortized
214212
215213#### Get Operation: $get(k) \rightarrow V \cup \{ \bot\} $
289287
290288** TTL Reset Behavior:**
291289
292- - TTL is only reset during ` set() ` operations when ` resetTtl = true ` and ` bypass = false `
290+ - TTL is reset during ` set() ` and ` setWithEvicted() ` operations when ` resetTtl = true `
293291- ` get() ` operations never reset TTL, regardless of the ` resetTtl ` setting
294- - ` setWithEvicted() ` operations reset TTL when ` resetTtl = true ` (does not use bypass parameter)
295292
296293### Space Complexity
297294
@@ -341,12 +338,8 @@ export class LRU<T> {
341338 get(key : any ): T | undefined ;
342339 has(key : any ): boolean ;
343340 keys(): any [];
344- set(key : any , value : T , bypass ? : boolean , resetTtl ? : boolean ): this ;
345- setWithEvicted(
346- key : any ,
347- value : T ,
348- resetTtl ? : boolean ,
349- ): { key: any ; value: T ; expiry: number } | null ;
341+ set(key : any , value : T ): this ;
342+ setWithEvicted(key : any , value : T ): { key: any ; value: T ; expiry: number } | null ;
350343 values(keys ? : any []): T [];
351344}
352345
0 commit comments