Skip to content

Commit

Permalink
Merge branch 'add_persistent_map_impl'
Browse files Browse the repository at this point in the history
* add_persistent_map_impl:
  lib: add `as_persistent_map` to `lock_free.map`
  • Loading branch information
maxteufel committed May 13, 2024
2 parents 467d3d3 + 437cfef commit 647910a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/container/Persistent_Map.fz
Expand Up @@ -30,5 +30,5 @@ public Persistent_Map(public K type : property.hashable, public V type) ref : Ma
# current Map and k,v.
# An already existing k will be replaced.
#
public put(k K, v V) Persistent_Map K V => abstract
public put(k K, v V) container.Persistent_Map K V => abstract

17 changes: 17 additions & 0 deletions modules/lock_free/src/lock_free/map.fz
Expand Up @@ -680,6 +680,23 @@ is
.as_list (i -> gcas_read i)


# this ctrie as a persistent map
#
# a snapshot is taken every time
# the map is modified.
#
as_persistent_map container.Persistent_Map CTK CTV =>
s := snapshot false
ref : container.Persistent_Map CTK CTV
public size i32 => s.size
public index [] (k CTK) option CTV => s[k]
public items Sequence (tuple CTK CTV) => s.items
public put(k CTK, v CTV) container.Persistent_Map CTK CTV =>
sp := s.snapshot false
sp.add k v
sp.as_persistent_map


# initialize a new ctrie
public fixed type.empty =>

Expand Down

0 comments on commit 647910a

Please sign in to comment.