1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs hashtables heaps kernel ;
6 TUPLE: assoc-heap assoc heap ;
8 C: <assoc-heap> assoc-heap
10 : <unique-min-heap> ( -- unique-heap )
11 H{ } clone <min-heap> <assoc-heap> ;
13 : <unique-max-heap> ( -- unique-heap )
14 H{ } clone <max-heap> <assoc-heap> ;
16 M: assoc-heap heap-push* ( value key assoc-heap -- entry )
17 pick over assoc>> key? [
20 [ assoc>> swapd set-at ] [ heap>> heap-push* ] 3bi
23 M: assoc-heap heap-pop ( assoc-heap -- value key )
26 M: assoc-heap heap-peek ( assoc-heap -- value key )
29 M: assoc-heap heap-empty? ( assoc-heap -- value key )