Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 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
Provides a Dictionary abstraction.
Documentation
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.
Four variants of the API are available:
- safe
- Performs argument and other constraint checks.
- unsafe
- Performs no constraint checks.
- safe synchronized
- Suffixes each procedure name with "/synch". All access to the dict object is synchronized.
- unsafe synchronized
- Suffixes each procedure name with "/%synch", except constructors & predicates which use "/synch".
Example:
- dict? is the name of the safe & unsafe variant's predicate, while dict?/synch is the safe synchronized and unsafe synchronized variant's name.
- dict-count is the name of the safe & unsafe variant's operation, while dict-count/synch is the safe synchronized name and dict-count/%synch the unsafe synchronized name.
make-dict
- make-dict #!optional EQUALITY ESTIMATEprocedure
Returns a dictionary using the supplied EQUALITY test, optimized for the number of elements ESTIMATE.
- EQUALITY
- procedure ; eq?
- ESTIMATE
- fixnum
alist->dict
- alist->dict ALIST EQUALITY #!optional ESTIMATEprocedure
Returns a dictionary constructed from ALIST using the supplied EQUALITY test, and optional ESTIMATE.
- EQUALITY
- procedure ; eq?
- ESTIMATE
- fixnum ; 0
dict?
- dict? OBJprocedure
Is the OBJ a dictionary?
dict-equivalence-function
- dict-equivalence-function DICTprocedure
Returns the equality test predicate procedure for DICT.
dict-count
- dict-count DICTprocedure
Returns the number of items in the DICT.
dict-keys
- dict-keys DICTprocedure
Returns the keys in the DICT.
dict-values
- dict-values DICTprocedure
Returns the values in the DICT.
dict->alist
- dict->alist DICTprocedure
Returns the DICT as an association list. The result may not be mutated!
dict-ref
- dict-ref DICT KEY #!optional DEFprocedure
Returns the value associated with KEY in the DICT, otherwise DEF.
- DEF
- * ; #f
dict-indempotent-ref!
- dict-indempotent-ref! DICT KEY FUNC #!optional DEFprocedure
Should a value for KEY exist in DICT it is returned. Otherwise FUNC is invoked on DEF. Any result other than DEF is the value for the KEY and that value is returned. Otherwise returns DEF.
- DEF
- * ; #f
dict-exists?
- dict-exists? DICT KEYprocedure
Does an entry with KEY exist in the DICT ?
dict-set!
- dict-set! DICT KEY VALprocedure
Associate VAL with KEY in the DICT.
VAL must not be (void)!
dict-update!
- dict-update! DICT KEY DEF-VAL-PROCEDURE #!optional FUNCprocedure
Invokes FUNC on either the existing value for KEY in the DICT, or the result of the DEF-VAL-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.
- FUNC
- (* -> *) ; identity
DEF-VAL-PROCEDURE must not return (void)!
dict-update-list!
- dict-update-list! DICT KEY OBJ ...procedure
Updates the value for KEY in the DICT with the OBJ list.
- OBJ ...
- (list-of *)
dict-update-dict!
- dict-update-dict! DICT KEY #!optional EQUALITY ESTIMATEprocedure
Updates the value for KEY in the DICT with a dict.
- EQUALITY
- procedure ; eq?; ESTIMATE : fixnum
dict-delete!
- dict-delete! DICT KEYprocedure
Removes any association of KEY in the DICT.
dict-for-each
- dict-for-each DICT PROCprocedure
Invokes the supplied PROC with each association in the DICT.
- PROC
- (KEY VAL -> void)
dict-merge!
- dict-merge! DICT DICT1 ...procedure
Returns the DICT as the (union DICT DICT1 ...) using overwrite semantics.
Tables must have the same equality predicate!
dict-search
- dict-search DICT PRED #!optional DEFprocedure
Returns the first entry value matched by the PRED. Otherwise the DEF value is returned.)
- PRED
- (KEY VAL --> boolean)
- DEF
- * ; #f
dict-print
- dict-print DICT #!optional PORTprocedure
Pretty-print DICT to PORT.
- PORT
- output-port ; (current-output-port)
Usage
- Safe variant
(require-extension lookup-table)
- Synchronized safe variant
(require-extension lookup-table-synch)
- Unsafe variant
(require-extension lookup-table-unsafe)
- Synchronized unsafe variant
(require-extension lookup-table-unsafe-synch)
Requirements
miscmacros check-errors record-variants synch dsssl-utils
Author
Version history
- 1.14.1
- Uses typed-define.
- 1.14.0
- Add types.
- 1.13.3
- Fix unsafe versions (not actually "unsafe").
- 1.13.2
- Fix for backwards incompatible use of module body string feature.
- 1.13.1
- Made dict-safe-mode a plain procedure since it is a no-op.
- 1.13.0
- Uses record-variants.
- 1.12.0
- Added 'make-dict' parameters to 'dict-update-dict!'.
- 1.11.0
- Added 'dict-Idempotent-ref!' and 'synch' versions.
- 1.10.0
- Split into safe & unsafe
- 1.9.1
- Fix for strange compile output (C procedures being redefined).
- 1.9.0
- Use of primitives.
- 1.8.0
- Chicken 4 release.
License
Copyright (C) 2009-2018 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.