Bug fixes for lcs.diff2html; xml.writer
[factor/jcg.git] / basis / assoc-heaps / assoc-heaps.factor
bloba495aed62634319a9f43f871f4d7961c47737920
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs hashtables heaps kernel ;
4 IN: assoc-heaps
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? [
18         3drop f
19     ] [
20         [ assoc>> swapd set-at ] [ heap>> heap-push* ] 3bi
21     ] if ;
23 M: assoc-heap heap-pop ( assoc-heap -- value key )
24     heap>> heap-pop ;
26 M: assoc-heap heap-peek ( assoc-heap -- value key )
27     heap>> heap-peek ;
29 M: assoc-heap heap-empty? ( assoc-heap -- value key )
30     heap>> heap-empty? ;