2title = "2k: Queue Logic"
11Container 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`.
39Test whether queue `a` is correctly ordered, producing a flag.
55 ?& ?~(l.a & ?&((mor n.a n.l.a) $(a l.a)))
56 ?~(r.a & ?&((mor n.a n.r.a) $(a r.a)))
63> =bad `(qeu @ud)`[1 ~ 2 ~ 3 ~ ~]
70> =good `(qeu @ud)`(~(gas to `(qeu @ud)`~) ~[1 2 3])
82Vertically rebalances queue `a`.
98 ?. |(?=(~ l.a) (mor n.a n.l.a))
99 $(a l.a(r $(a a(l r.l.a))))
100 ?. |(?=(~ r.a) (mor n.a n.r.a))
101 $(a r.a(l $(a a(r l.r.a))))
108> =a `(qeu @ud)`[1 ~ 2 ~ 3 ~ ~]
116> =z `(qeu @ud)`~(bal to a)
131Produces the maximum depth of leaves (`r.a` and `l.a`) in queue `a`.
147 +((max $(a l.a) $(a r.a)))
153> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 7 ~])
157> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 ~])
161> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 ~])
165> ~(dep to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~])
168> ~(dep to ~(bal to `(qeu tape)`["a" ~ "b" ~ "c" ~ "d" ~ "e" ~ "f" ~ "g" ~ ~]))
178Push all elements of list `b` into the queue `a`.
182`a` is a queue, and is the sample of `+to`.
194 |= b=(list _?>(?=(^ a) n.a))
196 ?~(b a $(b t.b, a (put i.b)))
202> `(qeu)`(~(gas to `(qeu @)`~) [1 2 3 ~])
205> =a (~(gas to `(qeu @)`~) [1 2 3 ~])
207> `(qeu)`(~(gas to a) b)
217Produces the head and tail queue of `a`.
225A cell of the last element in `a` along with the rest of queue `a`.
231 |- ^+ ?>(?=(^ a) [p=n.a q=*(tree _n.a)])
238 ?: |(?=(~ q.b) (mor n.a n.q.b))
240 a(n n.q.b, l a(r l.q.b), r r.q.b)
246> =s (~(gas to *(tree @)) `(list @)`~[1 2 3])
260Removes the head of queue `a`, producing the resulting queue.
277 bal(n.a p.b, l.a q.b)
283> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
292[n=6 l={} r={5 4 3 2 1}]
295[n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
308Removes the root of queue `a`, producing the resulting queue.
334> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
336[n=6 l={} r={5 4 3 2 1}]
339[n=2 l=[n=4 l={5} r={3}] r=[n=1 l={} r={}]]
348Accept noun `b` and adds to queue `a` as the head, producing the
353`a` is a queue, and is the sample of `+to`.
375> =a (~(gas to `(qeu @)`~) `(list @)`[3 1 2 4 5 6 ~])
376> `(qeu)`(~(put to a) 7)
386Produces queue `a` as a list from front to back.
400 =+ b=`(list _?>(?=(^ a) n.a))`~
402 =+ 0 :: hack for jet match
405 $(a r.a, b [n.a $(a l.a)])
411> =a (~(gas to `(qeu @)`~) [3 1 2 4 5 6 ~])
413[6 0 2 [4 [5 0 0] 0] 1 0 3 0 0]
425Produces the head of queue `a` as a `unit`.
439 |- ^- (unit _?>(?=(^ a) n.a))
441 ?~(r.a [~ n.a] $(a r.a))
447> =a (~(gas to `(qeu @)`~) `(list @)`[1 2 3 4 5 6 ~])
454An 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