aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/coll/sequence.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/coll/sequence.lux')
-rw-r--r--stdlib/source/lux/data/coll/sequence.lux68
1 files changed, 34 insertions, 34 deletions
diff --git a/stdlib/source/lux/data/coll/sequence.lux b/stdlib/source/lux/data/coll/sequence.lux
index f76c824a7..d8c3ddfb9 100644
--- a/stdlib/source/lux/data/coll/sequence.lux
+++ b/stdlib/source/lux/data/coll/sequence.lux
@@ -42,8 +42,8 @@
(-> Level Level)
(<op> branching-exponent))]
- [level-up n.+]
- [level-down n.-]
+ [level-up n/+]
+ [level-down n/-]
)
(def: full-node-size
@@ -52,7 +52,7 @@
(def: branch-idx-mask
Nat
- (n.dec full-node-size))
+ (n/dec full-node-size))
(def: branch-idx
(-> Index Index)
@@ -64,15 +64,15 @@
(def: (tail-off vec-size)
(-> Nat Nat)
- (if (n.< full-node-size vec-size)
+ (if (n/< full-node-size vec-size)
+0
- (|> (n.dec vec-size)
+ (|> (n/dec vec-size)
(bit;shift-right branching-exponent)
(bit;shift-left branching-exponent))))
(def: (new-path level tail)
(All [a] (-> Level (Base a) (Node a)))
- (if (n.= +0 level)
+ (if (n/= +0 level)
(#Base tail)
(|> ## (new-hierarchy [])
(: (Hierarchy ($ +0))
@@ -89,9 +89,9 @@
(def: (push-tail size level tail parent)
(All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a)))
- (let [sub-idx (branch-idx (bit;shift-right level (n.dec size)))
+ (let [sub-idx (branch-idx (bit;shift-right level (n/dec size)))
## If we're currently on a bottom node
- sub-node (if (n.= branching-exponent level)
+ sub-node (if (n/= branching-exponent level)
## Just add the tail to it
(#Base tail)
## Otherwise, check whether there's a vacant spot
@@ -112,9 +112,9 @@
(def: (expand-tail val tail)
(All [a] (-> a (Base a) (Base a)))
(let [tail-size (array;size tail)]
- (|> ## (array;new (n.inc tail-size))
+ (|> ## (array;new (n/inc tail-size))
(: (Base ($ +0))
- (array;new (n.inc tail-size)))
+ (array;new (n/inc tail-size)))
(array;copy tail-size +0 tail +0)
(array;write tail-size val)
)))
@@ -128,7 +128,7 @@
(array;write sub-idx (#Hierarchy (put' (level-down level) idx val sub-node))))
(^multi (#;Some (#Base base))
- (n.= +0 (level-down level)))
+ (n/= +0 (level-down level)))
(|> (array;clone hierarchy)
(array;write sub-idx (|> (array;clone base)
(array;write (branch-idx idx) val)
@@ -139,11 +139,11 @@
(def: (pop-tail size level hierarchy)
(All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a))))
- (let [sub-idx (branch-idx (bit;shift-right level (n.- +2 size)))]
- (cond (n.= +0 sub-idx)
+ (let [sub-idx (branch-idx (bit;shift-right level (n/- +2 size)))]
+ (cond (n/= +0 sub-idx)
#;None
- (n.> branching-exponent level)
+ (n/> branching-exponent level)
(do maybe;Monad<Maybe>
[base|hierarchy (array;read sub-idx hierarchy)
sub (case base|hierarchy
@@ -198,15 +198,15 @@
(All [a] (-> a (Sequence a) (Sequence a)))
## Check if there is room in the tail.
(let [vec-size (get@ #size vec)]
- (if (|> vec-size (n.- (tail-off vec-size)) (n.< full-node-size))
+ (if (|> vec-size (n/- (tail-off vec-size)) (n/< full-node-size))
## If so, append to it.
(|> vec
- (update@ #size n.inc)
+ (update@ #size n/inc)
(update@ #tail (expand-tail val)))
## Otherwise, push tail into the tree
## --------------------------------------------------------
## Will the root experience an overflow with this addition?
- (|> (if (n.> (bit;shift-left (get@ #level vec) +1)
+ (|> (if (n/> (bit;shift-left (get@ #level vec) +1)
(bit;shift-right branching-exponent vec-size))
## If so, a brand-new root must be established, that is
## 1-level taller.
@@ -222,20 +222,20 @@
(update@ #root (push-tail vec-size (get@ #level vec) (get@ #tail vec)))))
## Finally, update the size of the Sequence and grow a new
## tail with the new element as it's sole member.
- (update@ #size n.inc)
+ (update@ #size n/inc)
(set@ #tail (new-tail val)))
)))
(def: (base-for idx vec)
(All [a] (-> Index (Sequence a) (Maybe (Base a))))
(let [vec-size (get@ #size vec)]
- (if (and (n.>= +0 idx)
- (n.< vec-size idx))
- (if (n.>= (tail-off vec-size) idx)
+ (if (and (n/>= +0 idx)
+ (n/< vec-size idx))
+ (if (n/>= (tail-off vec-size) idx)
(#;Some (get@ #tail vec))
(loop [level (get@ #level vec)
hierarchy (get@ #root vec)]
- (case [(n.> branching-exponent level)
+ (case [(n/> branching-exponent level)
(array;read (branch-idx (bit;shift-right level idx)) hierarchy)]
[true (#;Some (#Hierarchy sub))]
(recur (level-down level) sub)
@@ -259,9 +259,9 @@
(def: #export (put idx val vec)
(All [a] (-> Nat a (Sequence a) (Sequence a)))
(let [vec-size (get@ #size vec)]
- (if (and (n.>= +0 idx)
- (n.< vec-size idx))
- (if (n.>= (tail-off vec-size) idx)
+ (if (and (n/>= +0 idx)
+ (n/< vec-size idx))
+ (if (n/>= (tail-off vec-size) idx)
(|> vec
## (update@ #tail (|>. array;clone (array;write (branch-idx idx) val)))
(update@ #tail (: (-> (Base ($ +0)) (Base ($ +0)))
@@ -290,16 +290,16 @@
empty
vec-size
- (if (|> vec-size (n.- (tail-off vec-size)) (n.> +1))
+ (if (|> vec-size (n/- (tail-off vec-size)) (n/> +1))
(let [old-tail (get@ #tail vec)
- new-tail-size (n.dec (array;size old-tail))]
+ new-tail-size (n/dec (array;size old-tail))]
(|> vec
- (update@ #size n.dec)
+ (update@ #size n/dec)
(set@ #tail (|> (array;new new-tail-size)
(array;copy new-tail-size +0 old-tail +0)))))
(maybe;assume
(do maybe;Monad<Maybe>
- [new-tail (base-for (n.- +2 vec-size) vec)
+ [new-tail (base-for (n/- +2 vec-size) vec)
#let [## [level' root'] (let [init-level (get@ #level vec)]
## (loop [level init-level
## root (maybe;default (new-hierarchy [])
@@ -308,7 +308,7 @@
## ## (maybe;default (new-hierarchy [])
## ## (pop-tail vec-size init-level (get@ #root vec))))
## ]
- ## (if (n.> branching-exponent level)
+ ## (if (n/> branching-exponent level)
## (case [(array;read +1 root) (array;read +0 root)]
## [#;None (#;Some (#Hierarchy sub-node))]
## (recur (level-down level) sub-node)
@@ -325,7 +325,7 @@
root (: (Hierarchy ($ +0))
(maybe;default (new-hierarchy [])
(pop-tail vec-size init-level (get@ #root vec))))]
- (if (n.> branching-exponent level)
+ (if (n/> branching-exponent level)
(case [(array;read +1 root) (array;read +0 root)]
[#;None (#;Some (#Hierarchy sub-node))]
(recur (level-down level) sub-node)
@@ -338,7 +338,7 @@
[level root]))))
]]
(wrap (|> vec
- (update@ #size n.dec)
+ (update@ #size n/dec)
(set@ #level level')
(set@ #root root')
(set@ #tail new-tail))))))
@@ -363,7 +363,7 @@
(def: #export empty?
(All [a] (-> (Sequence a) Bool))
- (|>. (get@ #size) (n.= +0)))
+ (|>. (get@ #size) (n/= +0)))
## [Syntax]
(syntax: #export (sequence [elems (p;some s;any)])
@@ -386,7 +386,7 @@
(struct: #export (Eq<Sequence> Eq<a>) (All [a] (-> (Eq a) (Eq (Sequence a))))
(def: (= v1 v2)
- (and (n.= (get@ #size v1) (get@ #size v2))
+ (and (n/= (get@ #size v1) (get@ #size v2))
(let [(^open "Node/") (Eq<Node> Eq<a>)]
(and (Node/= (#Base (get@ #tail v1))
(#Base (get@ #tail v2)))