Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

lookup-table

Purports to be a simple key -> value lookup table. Known as a 'Dictionary' in some circles. It attempts to optimize for speed of lookup by choosing different storage models.

  1. Outdated egg!
  2. lookup-table
  3. Documentation
    1. dict-safe-mode
    2. make-dict
    3. alist->dict
    4. dict?
    5. dict-equivalence-function
    6. dict-count
    7. dict-keys
    8. dict-values
    9. dict->alist
    10. dict-ref
    11. dict-exists?
    12. dict-set!
    13. dict-update!
    14. dict-update-list!
    15. dict-update-dict!
    16. dict-delete!
    17. dict-for-each
    18. dict-merge!
    19. dict-search
    20. dict-print
  4. Usage
  5. Examples
  6. Notes
  7. Requirements
  8. Bugs and Limitations
  9. Author
  10. Version history
  11. License

Documentation

dict-safe-mode

[parameter] (dict-safe-mode [FLAG #f])

Sets or gets the safe execution mode.

Enables or disables argument validation. Also literal object return.

make-dict

[procedure] (make-dict [EQUALITY eq?] [ESTIMATE <small-number>])

Returns a dictionary using the supplied EQUALITY test, optimized for the number of elements ESTIMATE.

alist->dict

[procedure] (alist->dict ALIST [EQUALITY eq?] [ESTIMATE 0])

Returns a dictionary constructed from ALIST using the supplied EQUALITY test, and optional ESTIMATE.

dict?

[procedure] (dict? OBJECT)

Is the OBJECT a dictionary?

dict-equivalence-function

[procedure] (dict-equivalence-function DICT)

Returns the equality test predicate procedure for DICT.

dict-count

[procedure] (dict-count DICT)

Returns the number of items in the DICT.

dict-keys

[procedure] (dict-keys DICT)

Returns the keys in the DICT.

dict-values

[procedure] (dict-values DICT)

Returns the values in the DICT.

dict->alist

[procedure] (dict->alist DICT)

Returns the DICT as an association list. The result may not be mutated!

dict-ref

[procedure] (dict-ref DICT KEY [DEFAULT #f])

Returns the value associated with KEY in the DICT, otherwise DEFAULT.

dict-exists?

[procedure] (dict-exists? DICT KEY)

Does an entry with KEY exist in the DICT ?

dict-set!

[procedure] (dict-set! DICT KEY VALUE)

Associate VALUE with KEY in the DICT.

VALUE must not be (code (void)) !

dict-update!

[procedure] (dict-update! DICT KEY DEFAULT-VALUE-PROCEDURE [FUNC identity])

Invokes FUNC on either the existing value for KEY in the DICT, or the result of the DEFAULT-VALUE-PROCEDURE when no existing value. The result then becomes the value for KEY in the DICT.

Returns the updated value for KEY in the DICT.

DEFAULT-VALUE-PROCEDURE must not return (code (void)) !

dict-update-list!

[procedure] (dict-update-list! DICT KEY [OBJECT]...)

Updates the value for KEY in the DICT with a list of OBJECT.

dict-update-dict!

[procedure] (dict-update-dict! DICT KEY)

Updates the value for KEY in the DICT with a dictionay.

dict-delete!

[procedure] (dict-delete! DICT KEY)

Removes any association of KEY in the DICT.

dict-for-each

[procedure] (dict-for-each DICT (PROCEDURE (-> KEY VALUE <ignored>)))

Invokes the supplied PROCEDURE with each association in the DICT.

dict-merge!

[procedure] (dict-merge! DICT [DICT-1...])

Returns the DICT as the union of ( DICT DICT-1 ...) using overwrite semantics.

Tables must have the same equality predicate.

[procedure] (dict-search DICT (PROCEDURE (-> object object boolean)) [DEFAULT #f])

Accepts a PROCEDURE of two arguments, key and value. When the procedure returns (code #t) this procedure returns the value. Otherwise the DEFAULT value is returned.)

dict-print

[procedure] (dict-print DICT [PORT (current-output-port)])

Pretty-print DICT to PORT.

Usage

(require-extension lookup-table

Examples

Notes

Requirements

miscmacros misc-extn

Bugs and Limitations

Author

kon lovett

Version history

1.7.0
Removed backward compatibility for 'make-dict' argument order.
1.6.0
Replaced dict-unsafe-mode with dict-safe-mode. The update operations now rebind storage model.
1.502
Added 'dict-keys', 'dict-values'
1.501
Uses 'misc-extn' 3.0
1.5
Added dict-exists?, dict-unsafe-mode
1.4
Added update procedures
1.3
Changed argument order for 'make-dict'
1.2
Needs misc-extn > 2.0
1.1
Added search, count
1.0
Initial release

License

Copyright (C) 2009 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.