shrub/arvo/behn.hoon

230 lines
7.3 KiB
Plaintext
Raw Normal View History

:: :: %behn, just a timer
!? 164
2015-12-14 10:58:14 +03:00
::::
2015-12-20 23:50:45 +03:00
|= pit/vase
2014-10-16 02:47:53 +04:00
=> =~
|%
2015-12-20 23:50:45 +03:00
++ sqeu |* {a/_* b/_*} :: binary skew queno
2015-12-21 00:16:39 +03:00
$: r/@u :: rank+depth
2015-12-20 23:50:45 +03:00
k/a :: priority
n/b :: value
c/(broq a b) :: children
== ::
2015-12-20 23:50:45 +03:00
++ broq |* {a/_* b/_*} :: brodal skew qeu
2014-10-16 02:47:53 +04:00
(list (sqeu a b)) ::
++ gift gift-behn :: out result <-$
++ kiss :: in request ->$
2015-12-20 23:50:45 +03:00
$% {$rest p/@da} :: cancel alarm
{$wait p/@da} :: set alarm
2015-12-06 00:49:32 +03:00
{$wake $~} :: timer activate
{$wegh $~} :: report memory
== ::
2015-12-20 23:50:45 +03:00
++ move {p/duct q/(mold note gift)} :: local move
2015-12-06 00:49:32 +03:00
++ note $~ :: out request $->
++ sign $~ :: in result $<-
++ clok (broq @da duct) :: stored timers
--
::
|%
2014-10-16 02:47:53 +04:00
++ raze
2015-12-20 23:50:45 +03:00
|= tym/{p/clok q/clok}
2014-10-16 02:47:53 +04:00
^+ tym
2015-05-22 00:34:06 +03:00
?~ p.tym tym
2014-10-16 02:47:53 +04:00
?~ q.tym tym
?: (gth p:~(get up p.tym) p:~(get up q.tym)) :: killed nonexisting
~& [%snooze-lost del=p:~(get up q.tym) top=p:~(get up p.tym)]
$(q.tym ~(pop up q.tym))
?: =(~(get up p.tym) ~(get up q.tym))
$(tym [~(pop up p.tym) ~(pop up q.tym)])
tym
::
++ up :: priority queue
2015-12-06 00:49:32 +03:00
=+ [key=@da val=duct]
=+ cmp=lte :: lte=min, gte=max
=> |%
++ link
2015-12-20 23:50:45 +03:00
|= {p/(sqeu key val) q/(sqeu key val)} :: link eq rank
2014-10-16 02:47:53 +04:00
^- (sqeu key val)
?> =(r.p r.q)
?: (cmp k.p k.q)
[r=+(r.p) k=k.p n=n.p c=[i=q t=c.p]]
[r=+(r.q) k=k.q n=n.q c=[i=p t=c.q]]
2014-10-16 02:47:53 +04:00
::
++ sink :: skew link
2015-12-20 23:50:45 +03:00
|= {p/(sqeu key val) q/(sqeu key val) r/(sqeu key val)}
2014-10-16 02:47:53 +04:00
^- (sqeu key val)
?: &((cmp k.q k.p) (cmp k.q k.r))
[r=+(r.q) k=k.q n=n.q c=[i=p t=[i=r t=c.q]]]
?: &((cmp k.r k.p) (cmp k.r k.q))
[r=+(r.r) k=k.r n=n.r c=[i=p t=[i=q t=c.r]]]
[r=+(r.q) k=k.p n=n.p c=[i=q t=[i=r t=~]]]
2014-10-16 02:47:53 +04:00
::
++ sert :: internal ins op
2015-12-20 23:50:45 +03:00
|= {p/(sqeu key val) q/(broq key val)}
2014-10-16 02:47:53 +04:00
^- (broq key val)
?~ q [p ~]
?> (lte r.p r.i.q)
?: (lth r.p r.i.q)
[i=p t=q]
$(p (link p i.q), q t.q)
2014-10-16 02:47:53 +04:00
::
++ uniq :: remove init dup
2015-12-20 23:50:45 +03:00
|= q/(broq key val)
?~ q ~
2014-10-16 02:47:53 +04:00
(sert i.q t.q)
::
++ meek :: unique meld
2015-12-20 23:50:45 +03:00
|= {p/(broq key val) q/(broq key val)}
2014-10-16 02:47:53 +04:00
^- (broq key val)
?~ p q
?~ q p
?: (lth r.i.p r.i.q)
[i.p $(p t.p)]
?: (lth r.i.q r.i.p)
[i.q $(q t.q)]
2014-10-16 02:47:53 +04:00
(sert (link i.p i.q) $(p t.p, q t.q))
::
++ mini :: getmin
2015-12-20 23:50:45 +03:00
|= q/(broq key val)
^- p/{(sqeu key val) (broq key val)}
2014-10-16 02:47:53 +04:00
?~ q ~|(%fatal-mini-empty !!)
?~ t.q [i=i.q t=~]
=+ [l r]=$(q t.q)
?: (cmp k.i.q k.l)
[i.q t.q]
[l [i.q r]]
2014-10-16 02:47:53 +04:00
::
++ spit :: split
2015-12-20 23:50:45 +03:00
|= {p/(broq key val) q/(list {k/key n/val}) r/(broq key val)}
^- {t/(broq key val) x/(list {k/key n/val})}
?~ r
[t=p x=q]
?: =(0 r.i.r)
$(q [[k=k.i.r n=n.i.r] q], r t.r)
$(p [i.r p], r t.r)
--
2015-12-20 23:50:45 +03:00
|_ a/(broq key val) :: public interface
2014-10-16 02:47:53 +04:00
++ put :: insert element
2015-12-20 23:50:45 +03:00
|= {k/key n/val}
^+ a
?~ a [i=[r=0 k=k n=n c=~] t=~]
?~ t.a [i=[r=0 k=k n=n c=~] t=a]
?: =(r.i.a r.i.t.a)
2014-10-16 02:47:53 +04:00
[i=(sink [r=0 k=k n=n c=~] i.a i.t.a) t=t.t.a]
[i=[r=0 k=k n=n c=~] t=a]
2014-10-16 02:47:53 +04:00
::
++ pop :: remove top
^+ a
2014-10-16 02:47:53 +04:00
=+ ?~ a ~|(%empty-broq-pop !!)
[l r]=(mini a)
=+ [t x]=(spit ~ ~ c.l)
=. a r
=. a (uni t)
(gas x)
2014-10-16 02:47:53 +04:00
::
++ gas
2015-12-20 23:50:45 +03:00
|= b/(list {k/key n/val})
^+ a
2015-12-20 23:50:45 +03:00
q:(roll b |=({{k/key n/val} q/_a} (put(a q) k n)))
2014-10-16 02:47:53 +04:00
::
2014-10-15 23:58:06 +04:00
++ tap
2015-12-20 23:50:45 +03:00
^- (list {k/key n/val})
2014-10-15 23:58:06 +04:00
?~ a ~
2014-10-16 02:47:53 +04:00
[get tap(a pop)]
::
++ get :: retrieve top
2015-12-20 23:50:45 +03:00
^- {p/key q/val}
2014-10-16 02:47:53 +04:00
?~ a ~|(%empty-broq-peek !!)
?~ t.a [k n]:i.a
2014-10-16 02:47:53 +04:00
=+ m=get(a t.a)
?.((cmp k.i.a p.m) m [k n]:i.a)
2014-10-16 02:47:53 +04:00
::
++ uni :: merge
2015-12-20 23:50:45 +03:00
|= q/(broq key val)
^+ a
2014-10-16 02:47:53 +04:00
(meek (uniq a) (uniq q))
--
--
. ==
2015-12-14 10:58:14 +03:00
=| $: $0 ::
2015-12-21 00:16:39 +03:00
tym/{p/clok q/clok} :: positive+negative
== ::
2015-12-20 23:50:45 +03:00
|= {now/@da eny/@ ski/sled} :: current invocation
^?
2015-12-21 00:16:39 +03:00
|% :: poke+peek pattern
++ call :: handle request
2015-12-20 23:50:45 +03:00
|= $: hen/duct
hic/(hypo (hobo kiss))
==
2015-12-20 23:50:45 +03:00
^- {p/(list move) q/_..^$}
=> %= . :: XX temporary
q.hic
^- kiss
2015-12-06 00:49:32 +03:00
?: ?=($soft -.q.hic)
:: ~& [%behn-call-soft (,@tas `*`-.p.q.hic)]
((hard kiss) p.q.hic)
?: (~(nest ut -:!>(*kiss)) | p.hic) q.hic
2015-12-06 00:49:32 +03:00
~& [%behn-call-flub (@tas `*`-.q.hic)]
((hard kiss) q.hic)
==
=^ mof tym
?- -.q.hic
2015-12-06 00:49:32 +03:00
$rest
2015-05-07 05:25:41 +03:00
=. q.tym (~(put up q.tym) p.q.hic hen)
=. tym (raze tym)
[~ tym]
::
2015-12-06 00:49:32 +03:00
$wait
2015-05-07 05:25:41 +03:00
=. p.tym (~(put up p.tym) p.q.hic hen)
=. tym (raze tym)
[~ tym]
::
2015-12-06 00:49:32 +03:00
$wake
2014-10-15 23:58:06 +04:00
|- ^+ [*(list move) tym]
2014-10-16 02:47:53 +04:00
=. tym (raze tym)
2014-10-15 23:58:06 +04:00
?: =([~ ~] tym) [~ tym] :: XX TMI
2015-05-22 00:34:06 +03:00
?: =(~ p.tym)
~& %weird-wake [~ tym]
2014-10-16 02:47:53 +04:00
=+ nex=~(get up p.tym)
?: (lte now p.nex) [~ tym]
2014-10-16 02:47:53 +04:00
=^ mof tym $(p.tym ~(pop up p.tym))
[[`move`[q.nex %give %wake ~] mof] tym]
2015-05-07 05:25:41 +03:00
::
2015-12-06 00:49:32 +03:00
$wegh
2015-05-07 05:25:41 +03:00
:_ tym :_ ~
:^ hen %give %mass
:- %behn
2015-05-07 05:25:41 +03:00
:- %|
2015-12-21 00:16:39 +03:00
:~ tym+`tym
2015-05-07 05:25:41 +03:00
==
==
[mof ..^$]
::
++ doze
2015-12-20 23:50:45 +03:00
|= {now/@da hen/duct}
2015-12-06 00:49:32 +03:00
^- (unit @da)
2014-10-15 23:58:06 +04:00
?~ p.tym ~
2014-10-16 02:47:53 +04:00
(some p:[~(get up p.tym)])
::
++ load
2015-12-20 23:50:45 +03:00
|= old/{$0 tym/{clok clok}}
^+ ..^$
..^$(tym tym.old)
::
++ scry
2015-12-20 23:50:45 +03:00
|= {fur/(unit (set monk)) ren/@tas his/ship syd/desk lot/coin tyl/path}
2015-12-06 00:49:32 +03:00
^- (unit (unit (pair mark *)))
2014-10-15 23:58:06 +04:00
=+ ^= liz
2015-12-06 00:49:32 +03:00
|- ^- (list {@da duct})
2014-10-16 02:47:53 +04:00
=. tym (raze tym)
2014-10-15 23:58:06 +04:00
?~ p.tym ~
2014-10-16 02:47:53 +04:00
[~(get up p.tym) $(p.tym ~(pop up p.tym))]
2014-10-15 23:58:06 +04:00
[~ ~ [%tank >liz<]]
::
2014-10-16 02:47:53 +04:00
++ stay [%0 tym]
++ take :: process move
2015-12-20 23:50:45 +03:00
|= {tea/wire hen/duct hin/(hypo sign)}
2015-12-08 10:57:19 +03:00
^+ [p=*(list move) q=..^$]
!!
--