2title = "2k: Queue Logic"
12Container arm for queue operation arms. The contained arms inherit `a`, its
28`tree` is the generic tree-shape mold. Maps, sets, and queues all share that
29shape, but they put their elements in different places and have different
30interfaces. `to` is the interface core for `qeu`; it's not generic across all
31the different containers that use `tree`.
38Vertically rebalances queue `a`.
54 ?. |(?=($~ l.a) (vor n.a n.l.a))
55 $(a [n.l.a l.l.a $(a [n.a r.l.a r.a])])
56 ?. |(?=($~ r.a) (vor n.a n.r.a))
57 $(a [n.r.a $(a [n.a l.a l.r.a]) r.r.a])
64 > `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
65 {"a" "b" "c" "d" "e" "f" "g"}
67 > `*`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]
68 [[97 0] 0 [98 0] 0 [99 0] 0 [100 0] 0 [101 0] 0 [102 0] 0 [103 0] 0 0]
70 > ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
71 [n=[i='d' t=""] l={"a" "b" "c"} r={"e" "f" "g"}]
73 > `*`~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
74 [[100 0] [[99 0] [[98 0] [[97 0] 0 0] 0] 0] [101 0] 0 [102 0] 0 [103 0] 0 0]
82Produces the maximum depth of leaves (`r.a` and `l.a`) in queue `a`.
98 +((max $(a l.a) $(a r.a)))
104 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
108 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
112 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
116 > ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
119 > ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
128Push all elements of list `b` into the queue `a`.
144 |= b=(list _?>(?=(^ a) n.a))
146 ?~(b a $(b t.b, a (put i.b)))
153 > `(qeu)`(~(gas to `(qeu @)`~) [1 2 3 ~])
156 > =a (~(gas to `(qeu @)`~) [1 2 3 ~])
158 > `(qeu)`(~(gas to a) b)
166Produces the head and tail queue of `a`.
174A cell of the last element in `a` along with the rest of queue `a`.
180 |- ^+ ?>(?=(^ a) [p=n.a q=*(tree _n.a)])
187 ?: |(?=($~ q.b) (vor n.a n.q.b))
189 [n.q.b [n.a l.a l.q.b] r.q.b]
195 > =s (~(gas to *(tree @)) `(list @)`~[1 2 3])
208Removes the head of queue `a`, producing the resulting queue.
225 bal(a ^+(a [p.b q.b r.a]))
231 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
240 [n=6 l={} r={5 4 3 2 1}]
243 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
255Removes the root of queue `a`, producing the resulting queue.
274 [n.l.a l.l.a $(l.a r.l.a)]
275 [n.r.a $(r.a l.r.a) r.r.a]
281 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
283 [n=6 l={} r={5 4 3 2 1}]
286 [n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
294Accept any noun `b` and adds to queue `a` as the head, producing the
321 > =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
322 > `(qeu)`(~(put to a) 7)
331Produces queue `a` as a list from front to back.
345 =| b=(list _?>(?=(^ a) n.a))
347 =+ 0 :: hack for jet match
350 $(a r.a, b [n.a $(a l.a)])
356 > =a (~(gas to `(qeu @)`~) [3 1 2 4 5 6 ~])
358 [6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
368Produces the head of queue `a` as a `unit`.
382 |- ^- (unit _?>(?=(^ a) n.a))
384 ?~(r.a [~ n.a] $(a r.a))
390 > =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
397An 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