assoc-deques -> assoc-heaps

db4
Doug Coleman 2008-10-01 20:48:53 -05:00
parent 0b57ce6c52
commit 32b3fab3a9
7 changed files with 66 additions and 66 deletions

View File

@ -1,32 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax io.streams.string ;
IN: assoc-deques
HELP: <assoc-deque>
{ $description "Constructs a new " { $link assoc-deque } " from two existing data structures." } ;
HELP: <unique-max-heap>
{ $values
{ "unique-heap" assoc-deque } }
{ $description "Creates a new " { $link assoc-deque } " where the assoc is a hashtable and the deque is a max-heap." } ;
HELP: <unique-min-heap>
{ $values
{ "unique-heap" assoc-deque } }
{ $description "Creates a new " { $link assoc-deque } " where the assoc is a hashtable and the deque is a min-heap." } ;
HELP: assoc-deque
{ $description "A data structure containing an assoc and a deque to get certain properties with better time constraints at the expense of more space and complexity. For instance, a hashtable and a heap can be combined into one assoc-deque to get a sorted data structure with O(1) lookup. Operations on assoc-deques should update both the assoc and the deque." } ;
ARTICLE: "assoc-deques" "Associative deques"
"The " { $vocab-link "assoc-deques" } " vocabulary combines exists to synthesize data structures with better time properties than either of the two component data structures alone." $nl
"Associative deque constructor:"
{ $subsection <assoc-deque> }
"Unique heaps:"
{ $subsection <unique-min-heap> }
{ $subsection <unique-max-heap> } ;
ABOUT: "assoc-deques"

View File

@ -1,31 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs deques hashtables heaps kernel ;
IN: assoc-deques
TUPLE: assoc-deque assoc deque ;
C: <assoc-deque> assoc-deque
: <unique-min-heap> ( -- unique-heap )
H{ } clone <min-heap> <assoc-deque> ;
: <unique-max-heap> ( -- unique-heap )
H{ } clone <max-heap> <assoc-deque> ;
M: assoc-deque heap-push* ( value key assoc-deque -- entry )
pick over assoc>> key? [
3drop f
] [
[ assoc>> swapd set-at ] [ deque>> heap-push* ] 3bi
] if ;
M: assoc-deque heap-pop ( assoc-deque -- value key )
[ deque>> heap-pop ] keep
[ over ] dip assoc>> delete-at ;
M: assoc-deque heap-peek ( assoc-deque -- value key )
deque>> heap-peek ;
M: assoc-deque heap-empty? ( assoc-deque -- value key )
deque>> heap-empty? ;

View File

@ -0,0 +1,32 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax io.streams.string ;
IN: assoc-heaps
HELP: <assoc-heap>
{ $description "Constructs a new " { $link assoc-heap } " from two existing data structures." } ;
HELP: <unique-max-heap>
{ $values
{ "unique-heap" assoc-heap } }
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a max-heap." } ;
HELP: <unique-min-heap>
{ $values
{ "unique-heap" assoc-heap } }
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a min-heap." } ;
HELP: assoc-heap
{ $description "A data structure containing an assoc and a heap to get certain properties with better time constraints at the expense of more space and complexity. For instance, a hashtable and a heap can be combined into one assoc-heap to get a sorted data structure with O(1) lookup. Operations on assoc-heap should update both the assoc and the heap." } ;
ARTICLE: "assoc-heaps" "Associative heaps"
"The " { $vocab-link "assoc-heaps" } " vocabulary combines exists to synthesize data structures with better time properties than either of the two component data structures alone." $nl
"Associative heap constructor:"
{ $subsection <assoc-heap> }
"Unique heaps:"
{ $subsection <unique-min-heap> }
{ $subsection <unique-max-heap> } ;
ABOUT: "assoc-heaps"

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: tools.test assoc-deques ; USING: tools.test assoc-heaps ;
IN: assoc-deques.tests IN: assoc-heaps.tests

View File

@ -0,0 +1,31 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs hashtables heaps kernel ;
IN: assoc-heaps
TUPLE: assoc-heap assoc heap ;
C: <assoc-heap> assoc-heap
: <unique-min-heap> ( -- unique-heap )
H{ } clone <min-heap> <assoc-heap> ;
: <unique-max-heap> ( -- unique-heap )
H{ } clone <max-heap> <assoc-heap> ;
M: assoc-heap heap-push* ( value key assoc-heap -- entry )
pick over assoc>> key? [
3drop f
] [
[ assoc>> swapd set-at ] [ heap>> heap-push* ] 3bi
] if ;
M: assoc-heap heap-pop ( assoc-heap -- value key )
[ heap>> heap-pop ] keep
[ over ] dip assoc>> delete-at ;
M: assoc-heap heap-peek ( assoc-heap -- value key )
heap>> heap-peek ;
M: assoc-heap heap-empty? ( assoc-heap -- value key )
heap>> heap-empty? ;

View File

@ -3,7 +3,7 @@
USING: accessors fry html.parser html.parser.analyzer USING: accessors fry html.parser html.parser.analyzer
http.client kernel tools.time sets assocs sequences http.client kernel tools.time sets assocs sequences
concurrency.combinators io threads namespaces math multiline concurrency.combinators io threads namespaces math multiline
heaps math.parser inspector urls assoc-deques logging heaps math.parser inspector urls assoc-heaps logging
combinators.short-circuit continuations calendar prettyprint ; combinators.short-circuit continuations calendar prettyprint ;
IN: spider IN: spider