Skip to content

Commit

Permalink
Merge pull request #4 from kubo39/set-visited-flag-true-when-the-key-…
Browse files Browse the repository at this point in the history
…is-updated

Fix: set node.visited true when the entry is updated
  • Loading branch information
lost22git authored May 19, 2024
2 parents 60e03e6 + 0ae8887 commit ba325bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sieve_cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ proc del*[K, V](cache: Cache[K, V], k: K): V =

proc add*[K, V](cache: Cache[K, V], k: K, v: sink V) =
if cache.has(k):
cache.getNodeFromStore(k).value = v
let node = cache.getNodeFromStore(k)
node.visited = true
node.value = v
else:
let node = Node[K, V](key: k, value: v)
cache.addNodeToStore(node)
Expand Down
10 changes: 10 additions & 0 deletions tests/tsieve_cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ test "chain":
cache["baz"] = 42
for node in cache.chain:
discard $node

test "update visited flag when the entry is updated":
let cache = newCache[string, string](2)
cache["key1"] = "value1"
cache["key2"] = "value2"
# update `key1` entry.
cache["key1"] = "updated"
# add new entry.
cache["key3"] = "value3"
check cache.has("key1")

0 comments on commit ba325bf

Please sign in to comment.