2title = "2k: Queue Logic"
11Container arm for queue operation arms. The contained arms inherit `a`, its
27`tree` is the generic tree-shape mold. Maps, sets, and queues all share that
28shape, but they put their elements in different places and have different
29interfaces. `to` is the interface core for `qeu`; it's not generic across all
30the different containers that use `tree`.
37Vertically rebalances queue `a`.
53 ?. |(?=($~ l.a) (vor n.a n.l.a))
54 $(a [n.l.a l.l.a $(a [n.a r.l.a r.a])])
55 ?. |(?=($~ r.a) (vor n.a n.r.a))
56 $(a [n.r.a $(a [n.a l.a l.r.a]) r.r.a])
63 > `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
64 {"a" "b" "c" "d" "e" "f" "g"}
66 > `*`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
67 [[97 0] 0 [98 0] 0 [99 0] 0 [100 0] 0 [101 0] 0 [102 0] 0 [103 0] 0 0]
69 > ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
70 [n=[i='d' t=""] l={"a" "b" "c"} r={"e" "f" "g"}]
72 > `*`~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
73 [[100 0] [[99 0] [[98 0] [[97 0] 0 0] 0] 0] [101 0] 0 [102 0] 0 [103 0] 0 0]
81Produces the maximum depth of leaves (`r.a` and `l.a`) in queue `a`.
97 +((max $(a l.a) $(a r.a)))
103 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
107 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
111 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
115 > ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
118 > ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
127Push all elements of list `b` into the queue `a`.
143 |= b=(list _?>(?=(^ a) n.a))
145 ?~(b a $(b t.b, a (put i.b)))
152 > `(qeu)`(~(gas to `(qeu @)`~) [1 2 3 ~])
155 > =a (~(gas to `(qeu @)`~) [1 2 3 ~])
157 > `(qeu)`(~(gas to a) b)
165Produces the head and tail queue of `a`.
173A cell of the last element in `a` along with the rest of queue `a`.
179 |- ^+ ?>(?=(^ a) [p=n.a q=*(tree _n.a)])
186 ?: |(?=($~ q.b) (vor n.a n.q.b))
188 [n.q.b [n.a l.a l.q.b] r.q.b]
194 > =s (~(gas to *(tree @)) `(list @)`~[1 2 3])
207Removes the head of queue `a`, producing the resulting queue.
224 bal(a ^+(a [p.b q.b r.a]))
230 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
239 [n=6 l={} r={5 4 3 2 1}]
242 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
254Removes the root of queue `a`, producing the resulting queue.
273 [n.l.a l.l.a $(l.a r.l.a)]
274 [n.r.a $(r.a l.r.a) r.r.a]
280 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
282 [n=6 l={} r={5 4 3 2 1}]
285 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
293Accept any noun `b` and adds to queue `a` as the head, producing the
320 > =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
321 > `(qeu)`(~(put to a) 7)
330Produces queue `a` as a list from front to back.
344 =| b=(list _?>(?=(^ a) n.a))
346 =+ 0 :: hack for jet match
349 $(a r.a, b [n.a $(a l.a)])
355 > =a (~(gas to `(qeu @)`~) [3 1 2 4 5 6 ~])
357 [6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
367Produces the head of queue `a` as a `unit`.
381 |- ^- (unit _?>(?=(^ a) n.a))
383 ?~(r.a [~ n.a] $(a r.a))
389 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
396An 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