source: project/wiki/eggref/4/lookup-table @ 15714

Last change on this file since 15714 was 15714, checked in by Kon Lovett, 11 years ago

Rel 1.9.1 of lookup-table.

File size: 4.9 KB
Line 
1[[tags: egg]]
2
3== lookup-table
4
5Purports to be a simple key -> value lookup table. Known as a
6'Dictionary' in some circles. It attempts to optimize for speed of
7lookup by choosing different storage models.
8
9[[toc:]]
10
11
12== Documentation
13
14=== dict-safe-mode
15
16<parameter>(dict-safe-mode [FLAG #f])</parameter>
17
18Sets or gets the safe execution mode.
19
20Enables or disables argument validation. Also literal object return.
21
22=== make-dict
23
24<procedure>(make-dict [EQUALITY eq?] [ESTIMATE <small-number>])</procedure>
25
26Returns a dictionary using the supplied {{EQUALITY}} test, optimized for the
27number of elements {{ESTIMATE}}.
28
29=== alist->dict
30
31<procedure>(alist->dict ALIST [EQUALITY eq?] [ESTIMATE 0])</procedure>
32
33Returns a dictionary constructed from {{ALIST}} using the supplied {{EQUALITY}}
34test, and optional {{ESTIMATE}}.
35
36=== dict?
37
38<procedure>(dict? OBJECT)</procedure>
39
40Is the {{OBJECT}} a dictionary?
41
42=== dict-equivalence-function
43
44<procedure>(dict-equivalence-function DICT)</procedure>
45
46Returns the equality test predicate procedure for {{DICT}}.
47
48=== dict-count
49
50<procedure>(dict-count DICT)</procedure>
51
52Returns the number of items in the {{DICT}}.
53
54=== dict-keys
55
56<procedure>(dict-keys DICT)</procedure>
57
58Returns the keys in the {{DICT}}.
59
60=== dict-values
61
62<procedure>(dict-values DICT)</procedure>
63
64Returns the values in the {{DICT}}.
65
66=== dict->alist
67
68<procedure>(dict->alist DICT)</procedure>
69
70Returns the {{DICT}} as an association list. The result may not be mutated!
71
72=== dict-ref
73
74<procedure>(dict-ref DICT KEY [DEFAULT #f])</procedure>
75
76Returns the value associated with {{KEY}} in the {{DICT}}, otherwise
77{{DEFAULT}}.
78
79=== dict-exists?
80
81<procedure>(dict-exists? DICT KEY)</procedure>
82
83Does an entry with {{KEY}} exist in the {{DICT}} ?
84
85=== dict-set!
86
87<procedure>(dict-set! DICT KEY VALUE)</procedure>
88
89Associate {{VALUE}} with {{KEY}} in the {{DICT}}.
90
91{{VALUE}} must not be  (code (void)) !
92
93=== dict-update!
94
95<procedure>(dict-update! DICT KEY DEFAULT-VALUE-PROCEDURE [FUNC identity])</procedure>
96
97Invokes {{FUNC}} on either the existing value for {{KEY}} in the {{DICT}}, or
98the result of the {{DEFAULT-VALUE-PROCEDURE}} when no existing value. The
99result then becomes the value for {{KEY}} in the {{DICT}}.
100
101Returns the updated value for {{KEY}} in the {{DICT}}.
102
103{{DEFAULT-VALUE-PROCEDURE}} must not return  (code (void)) !
104
105=== dict-update-list!
106
107<procedure>(dict-update-list! DICT KEY [OBJECT]...)</procedure>
108
109Updates the value for {{KEY}} in the {{DICT}} with a list of {{OBJECT}}.
110
111=== dict-update-dict!
112
113<procedure>(dict-update-dict! DICT KEY)</procedure>
114
115Updates the value for {{KEY}} in the {{DICT}} with a dictionay.
116
117=== dict-delete!
118
119<procedure>(dict-delete! DICT KEY)</procedure>
120
121Removes any association of {{KEY}} in the {{DICT}}.
122
123=== dict-for-each
124
125<procedure>(dict-for-each DICT (PROCEDURE (-> KEY VALUE <ignored>)))</procedure>
126
127Invokes the supplied {{PROCEDURE}} with each association in the {{DICT}}.
128
129=== dict-merge!
130
131<procedure>(dict-merge! DICT [DICT1...])</procedure>
132
133Returns the {{DICT}} as the union of ( {{DICT}} {{DICT1}} ...) using overwrite
134semantics.
135
136Tables must have the same equality predicate.
137
138=== dict-search
139
140<procedure>(dict-search DICT (PROCEDURE (-> object object boolean)) [DEFAULT #f])</procedure>
141
142Accepts a {{PROCEDURE}} of two arguments, key and value. When the procedure
143returns  (code #t)  this procedure returns the value. Otherwise the {{DEFAULT}}
144value is returned.)
145
146=== dict-print
147
148<procedure>(dict-print DICT [PORT (current-output-port)])</procedure>
149
150Pretty-print {{DICT}} to {{PORT}}.
151
152
153== Usage
154
155<enscript language=scheme>
156(require-extension lookup-table
157</enscript>
158
159
160== Examples
161
162
163== Notes
164
165
166== Requirements
167
168[[miscmacros]]
169[[check-errors]]
170[[srfi-9-ext]]
171
172
173== Bugs and Limitations
174
175
176== Author
177
178[[/users/kon lovett|kon lovett]]
179
180
181== Version history
182
183; 1.9.1 : Fix for strange compile output (C procedures being redefined).
184; 1.9.0 : Use of primitives.
185; 1.8.0 : Chicken 4 release.
186
187
188== License
189
190Copyright (C) 2009 Kon Lovett.  All rights reserved.
191
192Permission is hereby granted, free of charge, to any person obtaining a
193copy of this software and associated documentation files (the Software),
194to deal in the Software without restriction, including without limitation
195the rights to use, copy, modify, merge, publish, distribute, sublicense,
196and/or sell copies of the Software, and to permit persons to whom the
197Software is furnished to do so, subject to the following conditions:
198
199The above copyright notice and this permission notice shall be included
200in all copies or substantial portions of the Software.
201
202THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
203IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
204FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
205THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
206OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
207ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.