shrub/arvo/behn.hoon

233 lines
7.3 KiB
Plaintext
Raw Normal View History

:: :: %behn, just a timer
!? 164
2015-05-07 05:25:41 +03:00
!:::
2014-10-16 02:47:53 +04:00
|= pit=vase
=> =~
|%
2014-10-16 02:47:53 +04:00
++ sqeu |* [a=_,* b=_,*] :: binary skew queno
$: r=@u :: rank/depth
k=a :: priority
n=b :: value
2014-10-16 02:47:53 +04:00
c=(broq a b) :: children
== ::
2014-10-16 02:47:53 +04:00
++ broq |* [a=_,* b=_,*] :: brodal skew qeu
(list (sqeu a b)) ::
++ gift gift-behn :: out result <-$
++ kiss :: in request ->$
2014-10-15 23:58:06 +04:00
$% [%rest p=@da] :: cancel alarm
[%wait p=@da] :: set alarm
[%wake ~] :: timer activate
2015-05-07 05:25:41 +03:00
[%wegh ~] :: report memory
== ::
++ move ,[p=duct q=(mold note gift)] :: local move
++ note ,~ :: out request $->
++ sign ,~ :: in result $<-
2014-10-16 02:47:53 +04:00
++ clok (broq ,@da duct) :: stored timers
--
::
|%
2014-10-16 02:47:53 +04:00
++ raze
|= tym=[p=clok q=clok]
^+ 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
=+ [key=,@da val=duct]
=+ cmp=lte :: lte=min, gte=max
=> |%
++ link
2014-10-16 02:47:53 +04:00
|= [p=(sqeu key val) q=(sqeu key val)] :: link eq rank
^- (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
|= [p=(sqeu key val) q=(sqeu key val) r=(sqeu key val)]
^- (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
|= [p=(sqeu key val) q=(broq key val)]
^- (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
2014-10-16 02:47:53 +04:00
|= q=(broq key val)
?~ q ~
2014-10-16 02:47:53 +04:00
(sert i.q t.q)
::
++ meek :: unique meld
|= [p=(broq key val) q=(broq key val)]
^- (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
|= q=(broq key val)
^- p=[(sqeu key val) (broq key val)]
?~ 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
|= [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)
--
2014-10-16 02:47:53 +04:00
|_ a=(broq key val) :: public interface
++ put :: insert element
|= [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
|= b=(list ,[k=key n=val])
^+ a
2014-10-16 02:47:53 +04:00
q:(roll b |=([[k=key n=val] q=_a] (put(a q) k n)))
::
2014-10-15 23:58:06 +04:00
++ tap
^- (list ,[k=key n=val])
?~ a ~
2014-10-16 02:47:53 +04:00
[get tap(a pop)]
::
++ get :: retrieve top
^- [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
2014-10-16 02:47:53 +04:00
|= q=(broq key val)
^+ a
2014-10-16 02:47:53 +04:00
(meek (uniq a) (uniq q))
--
--
. ==
2014-10-16 02:47:53 +04:00
=| $: %0 ::
2014-10-16 02:05:48 +04:00
tym=[p=clok q=clok] :: positive/negative
== ::
|= [now=@da eny=@ ski=sled] :: current invocation
^?
|% :: poke/peek pattern
++ call :: handle request
|= $: hen=duct
hic=(hypo (hobo kiss))
==
^- [p=(list move) q=_..^$]
=> %= . :: XX temporary
q.hic
^- kiss
?: ?=(%soft -.q.hic)
:: ~& [%behn-call-soft (,@tas `*`-.p.q.hic)]
((hard kiss) p.q.hic)
?: (~(nest ut -:!>(*kiss)) | p.hic) q.hic
~& [%behn-call-flub (,@tas `*`-.q.hic)]
((hard kiss) q.hic)
==
=^ mof tym
?- -.q.hic
2015-05-07 05:25:41 +03:00
%rest
=. q.tym (~(put up q.tym) p.q.hic hen)
=. tym (raze tym)
[~ tym]
::
%wait
=. p.tym (~(put up p.tym) p.q.hic hen)
=. tym (raze tym)
[~ tym]
::
%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
::
%wegh
:_ tym :_ ~
:^ hen %give %mass
:- %behn
2015-05-07 05:25:41 +03:00
:- %|
:~ tym/`tym
==
==
[mof ..^$]
::
2015-05-07 05:00:58 +03:00
++ foo
%bar
::
++ doze
|= [now=@da hen=duct]
^- (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
2014-10-16 02:47:53 +04:00
|= old=[%0 tym=[clok clok]]
^+ ..^$
..^$(tym tym.old)
::
++ scry
|= [fur=(unit (set monk)) ren=@tas his=ship syd=desk lot=coin tyl=path]
^- (unit (unit (pair mark ,*)))
2014-10-15 23:58:06 +04:00
=+ ^= liz
|- ^- (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
|= [tea=wire hen=duct hin=(hypo sign)]
^- [p=(list move) q=_..^$]
!!
--