Guile Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme style auto-resizing hashtable (fwd)
On Wed, 18 Nov 1998, Jay Glascoe wrote:
> The source code, a makefile, and test scripts are available at
>
> http://www.giss.nasa.gov/~jglascoe/GUILE/
http://www.giss.nasa.gov/~jglascoe/GUILE/table.tar.gz
After losing face on the whole destructive consumers issue, I decided to
rename the hash tables from "hash-table" to simply "table".
16 useful procedures, not counting the 'v'/'q'/'x' variations.
*** predicate: ***
table? object
your basic predicate. Caution: this is not 100% fool-proof.
*** constructors: ***
make-table
make-tablev
make-tableq
make-tablex user-equal? user-hasher
*** translators: ***
list->table list [wrapper]
list->tablev list [wrapper]
list->tableq list [wrapper]
list->tablex list user-equal? user-hasher [wrapper]
return a table with key-value pairs (wrapper list-element)
"wrapper" defaults to identity.
(wrapper list-element) must be a pair for all list-elements.
Think of these as list object methods; the list argument
should appear first.
;; Useful applications of this method include:
;; (define keys->table
;; (lambda (keys) (list->table keys (lambda x x))))
table->list table [unwrapper]
return a list with elements (unwrapper key-value-pair)
for all key-value pairs in table "table".
"unwrapper" defaults to identity.
;; Useful applications of this method include:
;; (define table->keys
;; (lambda (table) (table->list table car)))
;; (define table->values
;; (lambda (table) (table->list table cdr)))
;;
;; Useful applications involving two translators:
;; (define table->tableq
;; (lambda (table) (list->tableq (table->list table))))
;; (define list->uniques
;; (lambda (el) (table->list (list->table (lambda x x)) car)))
;; (define table-map
;; (lambda (transformer table)
;; (list->table (table->list table
;; (lambda (pair)
;; (transformer (cons (car pair)
;; (cdr pair))))))))
*** behavior modifiers: ***
table-enable! table option
table-disable! table option
"option" should be one of 'auto-shrink, 'store-hash.
rebuild "table" if the "store-hash" option is toggled.
NOTE: all table constructors and list->table
converters return a table with both options ON.
*** the "Big 3" basic operations: ***
table-insert! table key value
table-lookup table key [not-here]
table-remove! table key [not-here]
*** unions and consumers: ***
table-add-pair! table pair
Insert the key-value pair "pair" into table
"table". Of course, "pair" must be a pair.
In particular, pair should be of the form (key . value)
table-add-list! table list [wrapper]
Could be written as
;; (for-each (lambda (elt)
;; (table-add-pair! table (wrapper elt)))
;; list)
"list" must be a list and "wrapper" should be
a one argument procedure. (wrapper list-element)
must be a pair for all of "list"'s elements.
"wrapper" defaults to the identity function.
Return value is unspecified.
;; Useful applications of this method include:
;; (define table-add-table!
;; (lambda (table1 table2)
;; (table-add-list! table1 (table->list table2))))
*** other stuff: ***
table-size table
return the number of entries in table "table".
table-clear! table
remove all entries from table "table".
return value is unspecified.
table-map pair-transformer table
return a new dictionary with key-value-pairs
(pair-transformer key-value-pair)
The pair arguments given to the transformer
are [shallow] copies of the key-value pairs in
"table".
"map" and "for-each" are standard fare for functional
languages. Think of "table-map" as a procedure object
oriented method; so the procedure "pair-transformer"
belongs in front.
;; Useful applications of this method include:
;; (define table-copy
;; (let ((id (lambda (x) x)))
;; (lambda (table) (table-map id table))))
;; (define table-invert
;; (let ((inv (lambda (pair) (cons (cdr pair) (car pair)))))
;; (lambda (table) (table-map inv table))))
table-for-each procedure table
apply "procedure", a procedure of two arguments, to all of
"table"'s keys and values (lambda (key value) (...))
return value is unspecified.
Think of "table-for-each" as a procedure object
oriented method; so "procedure" belongs in front.
table-stats table
Return an association list filled with interesting statistics
and general info about your table "table".
>
> Jay Glascoe
> original author of
> "The $ICPyramid Scheme"
> jglascoe@jay.giss.nasa.gov
>
>
Guile Home |
Main Index |
Thread Index