diff options
author | Marvin Borner | 2024-10-26 21:38:27 +0200 |
---|---|---|
committer | Marvin Borner | 2024-10-26 21:38:27 +0200 |
commit | 20e3e03914b128a77595e39ee909a42d425a5d4b (patch) | |
tree | b34a9071329becc83ad4e578d714dbb631e5e774 /std/Set.bruijn | |
parent | 0a64553fb3f97021eea303fc9ba8b26d67db709c (diff) |
Fixed balanced tree / set
Diffstat (limited to 'std/Set.bruijn')
-rw-r--r-- | std/Set.bruijn | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/std/Set.bruijn b/std/Set.bruijn index 5f64335..bec1645 100644 --- a/std/Set.bruijn +++ b/std/Set.bruijn @@ -3,6 +3,7 @@ # can currently only store Numbers (due to std/Tree/Balanced) :import std/Tree/Balanced T +:import std/List . # empty set empty T.empty ⧗ Set @@ -13,8 +14,19 @@ add T.insert ⧗ Number → Set → Set # returns true if a number is in a set has? T.has? ⧗ Number → Set → Boolean +:test (has? (+5) (add (+5) empty)) ([[1]]) +:test (has? (+5) empty) ([[0]]) + +# count of elements in set +size T.size ⧗ Set → Number + # converts a set to a list -list! T.list! ⧗ Set → (List Number) +set→list T.tree→list ⧗ Set → (List Number) # converts a list to a set -from-list T.from-list ⧗ (List Number) → Set +list→set T.list→tree ⧗ (List Number) → Set + +:test (has? (+0) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[1]]) +:test (has? (+5) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[1]]) +:test (has? (+6) (list→set ((+5) : ((+3) : ((+2) : ((+1) : {}(+0))))))) ([[0]]) +:test (has? (+7) (list→set ((+5) : ((+7) : {}(+1))))) ([[1]]) |