mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +03:00
Merge remote-tracking branch 'origin/ted/ordered-map-fix' into release/next-sys
This commit is contained in:
commit
6215137ed5
@ -829,7 +829,7 @@
|
||||
:: lifecycle arms; mostly pass-throughs to the contained adult ames
|
||||
::
|
||||
++ scry scry:adult-core
|
||||
++ stay [%4 %larva queued-events ames-state.adult-gate]
|
||||
++ stay [%5 %larva queued-events ames-state.adult-gate]
|
||||
++ load
|
||||
|= $= old
|
||||
$% $: %4
|
||||
@ -839,6 +839,13 @@
|
||||
==
|
||||
[%adult state=_ames-state.adult-gate]
|
||||
== ==
|
||||
$: %5
|
||||
$% $: %larva
|
||||
events=(qeu queued-event)
|
||||
state=_ames-state.adult-gate
|
||||
==
|
||||
[%adult state=_ames-state.adult-gate]
|
||||
== ==
|
||||
==
|
||||
?- old
|
||||
[%4 %adult *] (load:adult-core %4 state.old)
|
||||
@ -848,6 +855,14 @@
|
||||
=. queued-events events.old
|
||||
=. adult-gate (load:adult-core %4 state.old)
|
||||
larval-gate
|
||||
::
|
||||
[%5 %adult *] (load:adult-core %5 state.old)
|
||||
::
|
||||
[%5 %larva *]
|
||||
~> %slog.1^leaf/"ames: larva: load"
|
||||
=. queued-events events.old
|
||||
=. adult-gate (load:adult-core %5 state.old)
|
||||
larval-gate
|
||||
==
|
||||
--
|
||||
:: adult ames, after metamorphosis from larva
|
||||
@ -919,13 +934,38 @@
|
||||
[moves ames-gate]
|
||||
:: +stay: extract state before reload
|
||||
::
|
||||
++ stay [%4 %adult ames-state]
|
||||
++ stay [%5 %adult ames-state]
|
||||
:: +load: load in old state after reload
|
||||
::
|
||||
++ load
|
||||
|= old-state=[%4 ^ames-state]
|
||||
|= $= old-state
|
||||
$% [%4 ^ames-state]
|
||||
[%5 ^ames-state]
|
||||
==
|
||||
|^
|
||||
^+ ames-gate
|
||||
=? old-state ?=(%4 -.old-state) %5^(state-4-to-5 +.old-state)
|
||||
::
|
||||
?> ?=(%5 -.old-state)
|
||||
ames-gate(ames-state +.old-state)
|
||||
::
|
||||
++ state-4-to-5
|
||||
|= =^ames-state
|
||||
^- ^^ames-state
|
||||
=. peers.ames-state
|
||||
%- ~(run by peers.ames-state)
|
||||
|= =ship-state
|
||||
?. ?=(%known -.ship-state)
|
||||
ship-state
|
||||
=. snd.ship-state
|
||||
%- ~(run by snd.ship-state)
|
||||
|= =message-pump-state
|
||||
=. num-live.metrics.packet-pump-state.message-pump-state
|
||||
~(wyt in live.packet-pump-state.message-pump-state)
|
||||
message-pump-state
|
||||
ship-state
|
||||
ames-state
|
||||
--
|
||||
:: +scry: dereference namespace
|
||||
::
|
||||
++ scry
|
||||
@ -1918,7 +1958,9 @@
|
||||
=+ ?~ dud ~
|
||||
%. ~
|
||||
%+ slog leaf+"ames: {<her.channel>} ack crashed {<mote.u.dud>}"
|
||||
?.(msg.veb ~ tang.u.dud)
|
||||
?. msg.veb ~
|
||||
:- >[bone=bone message-num=message-num meat=meat]:shut-packet<
|
||||
tang.u.dud
|
||||
(run-message-pump bone %hear [message-num +.meat]:shut-packet)
|
||||
:: +on-memo: handle request to send message
|
||||
::
|
||||
|
@ -5230,55 +5230,47 @@
|
||||
=/ acc [stop=`?`%.n state=state]
|
||||
=< abet =< main
|
||||
|%
|
||||
++ this .
|
||||
++ abet [state.acc a]
|
||||
:: +main: main recursive loop; performs a partial inorder traversal
|
||||
::
|
||||
++ main
|
||||
^+ .
|
||||
^+ this
|
||||
:: stop if empty or we've been told to stop
|
||||
::
|
||||
?~ a .
|
||||
?: stop.acc .
|
||||
?: =(~ a) this
|
||||
?: stop.acc this
|
||||
:: inorder traversal: left -> node -> right, until .f sets .stop
|
||||
::
|
||||
=> left
|
||||
?: stop.acc .
|
||||
=> node
|
||||
?: stop.acc .
|
||||
right
|
||||
=. this left
|
||||
?: stop.acc this
|
||||
=^ del this node
|
||||
=? this !stop.acc right
|
||||
=? a del (nip a)
|
||||
this
|
||||
:: +node: run .f on .n.a, updating .a, .state, and .stop
|
||||
::
|
||||
++ node
|
||||
^+ .
|
||||
^+ [del=*? this]
|
||||
:: run .f on node, updating .stop.acc and .state.acc
|
||||
::
|
||||
=^ res acc
|
||||
?> ?=(^ a)
|
||||
(f state.acc n.a)
|
||||
:: apply update to .a from .f's product
|
||||
::
|
||||
=. a
|
||||
:: if .f requested node deletion, merge and balance .l.a and .r.a
|
||||
::
|
||||
?~ res (nip a)
|
||||
:: we kept the node; replace its .val; order is unchanged
|
||||
::
|
||||
?> ?=(^ a)
|
||||
a(val.n u.res)
|
||||
::
|
||||
..node
|
||||
?> ?=(^ a)
|
||||
=^ res acc (f state.acc n.a)
|
||||
?~ res
|
||||
[del=& this]
|
||||
[del=| this(val.n.a u.res)]
|
||||
:: +left: recurse on left subtree, copying mutant back into .l.a
|
||||
::
|
||||
++ left
|
||||
^+ .
|
||||
?~ a .
|
||||
^+ this
|
||||
?~ a this
|
||||
=/ lef main(a l.a)
|
||||
lef(a a(l a.lef))
|
||||
:: +right: recurse on right subtree, copying mutant back into .r.a
|
||||
::
|
||||
++ right
|
||||
^+ .
|
||||
?~ a .
|
||||
^+ this
|
||||
?~ a this
|
||||
=/ rig main(a r.a)
|
||||
rig(a a(r a.rig))
|
||||
--
|
||||
|
@ -129,6 +129,30 @@
|
||||
!> -.b
|
||||
==
|
||||
::
|
||||
++ test-ordered-map-traverse-delete-all ^- tang
|
||||
;: weld
|
||||
=/ q ((ordered-map ,@ ,~) lte)
|
||||
=/ o (gas:q ~ ~[1/~ 2/~ 3/~])
|
||||
=/ b ((traverse:q ,~) o ~ |=([~ key=@ ~] [~ %| ~]))
|
||||
%+ expect-eq
|
||||
!> [~ ~]
|
||||
!> b
|
||||
::
|
||||
=/ c
|
||||
:~ [[2.127 1] ~] [[2.127 2] ~] [[2.127 3] ~]
|
||||
[[2.127 7] ~] [[2.127 8] ~] [[2.127 9] ~]
|
||||
==
|
||||
=/ compare
|
||||
|= [[aa=@ ab=@] [ba=@ bb=@]]
|
||||
?:((lth aa ba) %.y ?:((gth aa ba) %.n (lte ab bb)))
|
||||
=/ q ((ordered-map ,[@ @] ,~) compare)
|
||||
=/ o (gas:q ~ c)
|
||||
=/ b ((traverse:q ,~) o ~ |=([~ key=[@ @] ~] [~ %| ~]))
|
||||
%+ expect-eq
|
||||
!> [~ ~]
|
||||
!> b
|
||||
==
|
||||
::
|
||||
++ test-ordered-map-uni ^- tang
|
||||
::
|
||||
=/ a=(tree [@ud @tas]) (gas:atom-map ~ (scag 4 test-items))
|
||||
|
Loading…
Reference in New Issue
Block a user