fixed heap-push-all
parent
ec89ee67c6
commit
ded88583ef
|
@ -6,7 +6,6 @@ IN: heaps
|
|||
MIXIN: priority-queue
|
||||
|
||||
GENERIC: heap-push ( value key heap -- )
|
||||
GENERIC: heap-push-all ( assoc heap -- )
|
||||
GENERIC: heap-peek ( heap -- value key )
|
||||
GENERIC: heap-pop* ( heap -- )
|
||||
GENERIC: heap-pop ( heap -- value key )
|
||||
|
@ -107,7 +106,7 @@ M: priority-queue heap-push ( value key heap -- )
|
|||
[ heap-data ] keep
|
||||
up-heap ;
|
||||
|
||||
M: priority-queue heap-push-all ( assoc heap -- )
|
||||
: heap-push-all ( assoc heap -- )
|
||||
[ swapd heap-push ] curry assoc-each ;
|
||||
|
||||
M: priority-queue heap-peek ( heap -- value key )
|
||||
|
|
|
@ -44,3 +44,12 @@ T{
|
|||
T{ max-heap T{ heap f V{ { 1 2 } { 0 1 } } } }
|
||||
} heap-pop
|
||||
] unit-test
|
||||
|
||||
[
|
||||
T{
|
||||
assoc-heap
|
||||
f
|
||||
H{ { 1 2 } { 3 4 } }
|
||||
T{ min-heap T{ heap f V{ { 2 1 } { 4 3 } } } }
|
||||
}
|
||||
] [ H{ { 1 2 } { 3 4 } } H{ } clone <assoc-min-heap> [ heap-push-all ] keep ] unit-test
|
||||
|
|
|
@ -40,9 +40,6 @@ M: assoc-heap heap-peek ( assoc-heap -- value key )
|
|||
M: assoc-heap heap-push ( value key assoc-heap -- )
|
||||
set-at ;
|
||||
|
||||
M: assoc-heap heap-push-all ( assoc assoc-heap -- )
|
||||
swap [ rot set-at ] curry* each ;
|
||||
|
||||
M: assoc-heap heap-pop ( assoc-heap -- value key )
|
||||
dup assoc-heap-heap heap-pop swap
|
||||
rot dupd assoc-heap-assoc delete-at ;
|
||||
|
|
Loading…
Reference in New Issue