3 title/'2k: Queue Logic'
16Container arm for queue operation arms. The contained arms inherit `a`, its
32`tree` is the generic tree-shape mold. Maps, sets, and queues all share that
33shape, but they put their elements in different places and have different
34interfaces. `to` is the interface core for `qeu`; it's not generic across all
35the different containers that use `tree`.
42Vertically rebalances queue `a`.
58 ?. |(?=($~ l.a) (vor n.a n.l.a))
59 $(a [n.l.a l.l.a $(a [n.a r.l.a r.a])])
60 ?. |(?=($~ r.a) (vor n.a n.r.a))
61 $(a [n.r.a $(a [n.a l.a l.r.a]) r.r.a])
68 > `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
69 {"a" "b" "c" "d" "e" "f" "g"}
71 > `*`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
72 [[97 0] 0 [98 0] 0 [99 0] 0 [100 0] 0 [101 0] 0 [102 0] 0 [103 0] 0 0]
74 > ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
75 [n=[i='d' t=""] l={"a" "b" "c"} r={"e" "f" "g"}]
77 > `*`~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
78 [[100 0] [[99 0] [[98 0] [[97 0] 0 0] 0] 0] [101 0] 0 [102 0] 0 [103 0] 0 0]
86Produces the maximum depth of leaves (`r.a` and `l.a`) in queue `a`.
102 +((max $(a l.a) $(a r.a)))
108 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
112 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
116 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
120 > ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
123 > ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
132Push all elements of list `b` into the queue `a`.
148 |= b=(list _?>(?=(^ a) n.a))
150 ?~(b a $(b t.b, a (put i.b)))
157 > `(qeu)`(~(gas to `(qeu @)`~) [1 2 3 ~])
160 > =a (~(gas to `(qeu @)`~) [1 2 3 ~])
162 > `(qeu)`(~(gas to a) b)
170Produces the head and tail queue of `a`.
178A cell of the last element in `a` along with the rest of queue `a`.
184 |- ^+ ?>(?=(^ a) [p=n.a q=*(tree _n.a)])
191 ?: |(?=($~ q.b) (vor n.a n.q.b))
193 [n.q.b [n.a l.a l.q.b] r.q.b]
199 > =s (~(gas to *(tree @)) `(list @)`~[1 2 3])
212Removes the head of queue `a`, producing the resulting queue.
229 bal(a ^+(a [p.b q.b r.a]))
235 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
244 [n=6 l={} r={5 4 3 2 1}]
247 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
259Removes the root of queue `a`, producing the resulting queue.
278 [n.l.a l.l.a $(l.a r.l.a)]
279 [n.r.a $(r.a l.r.a) r.r.a]
285 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
287 [n=6 l={} r={5 4 3 2 1}]
290 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
298Accept any noun `b` and adds to queue `a` as the head, producing the
325 > =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
326 > `(qeu)`(~(put to a) 7)
335Produces queue `a` as a list from front to back.
349 =| b=(list _?>(?=(^ a) n.a))
351 =+ 0 :: hack for jet match
354 $(a r.a, b [n.a $(a l.a)])
360 > =a (~(gas to `(qeu @)`~) [3 1 2 4 5 6 ~])
362 [6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
372Produces the head of queue `a` as a `unit`.
386 |- ^- (unit _?>(?=(^ a) n.a))
388 ?~(r.a [~ n.a] $(a r.a))
394 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
401An empty queue has no head.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list