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

Last change on this file since 15811 was 15811, checked in by Kon Lovett, 10 years ago

Rel 1.10.0

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