source: project/chicken/trunk/manual/Unit srfi-69 @ 13740

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

Ordered by srfi #. Added srfi-69.

File size: 7.7 KB
Line 
1[[tags: manual]]
2[[toc:]]
3
4== Unit srfi-69
5
6CHICKEN implements SRFI 69 with SRFI 90 extensions. For more information, see
7[[http://srfi.schemers.org/srfi-69/srfi-69.html|SRFI-69]] and
8[[http://srfi.schemers.org/srfi-90/srfi-90.html|SRFI-90]].
9
10
11=== Hash Table Procedures
12
13
14==== make-hash-table
15
16 [procedure] (make-hash-table [TEST HASH SIZE] [#:test TEST] [#:hash HASH] [#:size SIZE] [#:initial INITIAL] [#:min-load MIN-LOAD] [#:max-load MAX-LOAD] [#:weak-keys WEAK-KEYS] [#:weak-values WEAK-VALUES])
17
18Returns a new {{HASH-TABLE}} with the supplied configuration.
19
20; {{TEST}} : The equivalence function.
21; {{HASH}} : The hash function.
22; {{SIZE}} : The expected number of table elements.
23; {{INITIAL}} : The default initial value.
24; {{MIN-LOAD}} : The minimum load factor. A {{flonum}} in (0.0 1.0).
25; {{MAX-LOAD}} : The maximum load factor. A {{flonum}} in (0.0 1.0).
26; {{WEAK-KEYS}} : Use weak references for keys. (Ignored)
27; {{WEAK-VALUES}} : Use weak references for values. (Ignored)
28
29
30==== alist->hash-table
31
32 [procedure] (alist->hash-table A-LIST [#:test TEST] [#:hash HASH] [#:size SIZE] [#:initial INITIAL] [#:min-load MIN-LOAD] [#:max-load MAX-LOAD] [#:weak-keys WEAK-KEYS] [#:weak-values WEAK-VALUES])
33
34Returns a new {{HASH-TABLE}}. The {{HASH-TABLE}} is populated from the
35{{A-LIST}}. The keyword arguments are per {{make-hash-table}}.
36
37
38==== hash-table?
39
40 [procedure] (hash-table? OBJECT)
41
42Is the {{OBJECT}} a {{hash-table}}?
43
44
45==== hash-table-size
46
47 [procedure] (hash-table-size HASH-TABLE)
48
49The {{HASH-TABLE}} size.
50
51
52==== hash-table-equivalence-function
53
54 [procedure] (hash-table-equivalence-function HASH-TABLE)
55
56The {{HASH-TABLE}} {{equivalence-function}}.
57
58
59==== hash-table-hash-function
60
61 [procedure] (hash-table-hash-function HASH-TABLE)
62
63The {{HASH-TABLE}} {{hash-function}}.
64
65
66==== hash-table-min-load
67
68 [procedure] (hash-table-min-load HASH-TABLE)
69
70The {{HASH-TABLE}} minimum load factor.
71
72
73==== hash-table-max-load
74
75 [procedure] (hash-table-max-load HASH-TABLE)
76
77The {{HASH-TABLE}} maximum load factor.
78
79
80==== hash-table-weak-keys
81
82 [procedure] (hash-table-weak-keys HASH-TABLE)
83
84Does the {{HASH-TABLE}} weak references for keys?
85
86
87==== hash-table-weak-values
88
89 [procedure] (hash-table-weak-values HASH-TABLE)
90
91Does the {{HASH-TABLE}} weak references for values?
92
93
94==== hash-table-has-initial?
95
96 [procedure] (hash-table-has-initial? HASH-TABLE)
97
98Does the {{HASH-TABLE}} have a default initial value?
99
100
101==== hash-table-initial
102
103 [procedure] (hash-table-initial HASH-TABLE)
104
105The {{HASH-TABLE}} default initial value.
106
107
108==== hash-table-keys
109
110 [procedure] (hash-table-keys HASH-TABLE)
111
112Returns a list of the keys in the {{HASH-TABLE}} population.
113
114
115==== hash-table-values
116
117 [procedure] (hash-table-values HASH-TABLE)
118
119Returns a list of the values in the {{HASH-TABLE}} population.
120
121
122==== hash-table->alist
123
124 [procedure] (hash-table->alist HASH-TABLE)
125
126Returns the population of the {{HASH-TABLE}} as an {{a-list}}.
127
128
129
130==== hash-table-ref
131
132 [procedure] (hash-table-ref HASH-TABLE KEY)
133
134Returns the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}.
135
136Aborts with an exception when the {{KEY}} is missing.
137
138
139==== hash-table-ref/default
140
141 [procedure] (hash-table-ref/default HASH-TABLE KEY DEFAULT)
142
143Returns the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}, or the {{DEFAULT}}
144when the {{KEY}} is missing.
145
146
147==== hash-table-exists?
148
149 [procedure] (hash-table-exists? HASH-TABLE KEY)
150
151Does the {{KEY}} exist in the {{HASH-TABLE}}?
152
153
154==== hash-table-set!
155
156 [procedure] (hash-table-set! HASH-TABLE KEY VALUE)
157
158Set the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}.
159
160A setter for {{hash-table-ref}} is defined, so
161
162<enscript highlight=scheme>
163(set! (hash-table-ref HASH-TABLE KEY) VALUE)
164</enscript>
165
166is equivalent to
167
168<enscript highlight=scheme>
169(hash-table-set! HASH-TABLE KEY VALUE)
170</enscript>
171
172
173==== hash-table-update!
174
175 [procedure] (hash-table-update! HASH-TABLE KEY [UPDATE-FUNCTION [DEFAULT-VALUE-FUNCTION]])
176
177Sets or replaces the {{VALUE}} for {{KEY}} in the {{HASH-TABLE}}.
178
179The {{UPDATE-FUNCTION}} takes the existing {{VALUE}} for {{KEY}} and returns
180the new {{VALUE}}. The default is {{identity}}
181
182The {{DEFAULT-VALUE-FUNCTION}} is called when the entry for {{KEY}} is missing.
183The default uses the {{(hash-table-initial-value)}}, if provided. Otherwise
184aborts with an exception.
185
186Returns the new {{VALUE}}.
187
188
189==== hash-table-update!/default
190
191 [procedure] (hash-table-update! HASH-TABLE KEY UPDATE-FUNCTION DEFAULT-VALUE)
192
193Sets or replaces the {{VALUE}} for {{KEY}} in the {{HASH-TABLE}}.
194
195The {{UPDATE-FUNCTION}} takes the existing {{VALUE}} for {{KEY}} and returns
196the new {{VALUE}}.
197
198The {{DEFAULT-VALUE}} is used when the entry for {{KEY}} is missing.
199
200Returns the new {{VALUE}}.
201
202
203==== hash-table-copy
204
205 [procededure] (hash-table-copy HASH-TABLE)
206
207Returns a shallow copy of the {{HASH-TABLE}}.
208
209
210==== hash-table-delete!
211
212 [procedure] (hash-table-delete! HASH-TABLE KEY)
213
214Deletes the entry for {{KEY}} in the {{HASH-TABLE}}.
215
216
217==== hash-table-remove!
218
219 [procedure] (hash-table-remove! HASH-TABLE PROC)
220
221Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
222entry. If {{PROC}} returns true, then that entry is removed.
223
224
225==== hash-table-clear!
226
227 [procedure] (hash-table-clear! HASH-TABLE)
228
229Deletes all entries in {{HASH-TABLE}}.
230
231
232==== hash-table-merge
233
234 [procedure] (hash-table-merge HASH-TABLE-1 HASH-TABLE-2)
235
236Returns a new {{HASH-TABLE}} with the union of {{HASH-TABLE-1}} and
237{{HASH-TABLE-2}}.
238
239
240==== hash-table-merge!
241
242 [procedure] (hash-table-merge! HASH-TABLE-1 HASH-TABLE-2)
243
244Returns {{HASH-TABLE-1}} as the union of {{HASH-TABLE-1}} and
245{{HASH-TABLE-2}}.
246
247
248==== hash-table-map
249
250 [procedure] (hash-table-map HASH-TABLE FUNC)
251
252Calls {{FUNC}} for all entries in {{HASH-TABLE}} with the key and value of each
253entry.
254
255Returns a list of the results of each call.
256
257
258==== hash-table-fold
259
260 [procedure] (hash-table-fold HASH-TABLE FUNC INIT)
261
262Calls {{FUNC}} for all entries in {{HASH-TABLE}} with the key and value of each
263entry, and the current folded value. The initial folded value is {{INIT}}.
264
265Returns the final folded value.
266
267
268==== hash-table-for-each
269
270 [procedure] (hash-table-for-each HASH-TABLE PROC)
271
272Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
273entry.
274
275
276==== hash-table-walk
277
278 [procedure] (hash-table-walk HASH-TABLE PROC)
279
280Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
281entry.
282
283
284=== Hashing Functions
285
286All hash functions return a {{fixnum}} in the range [0 {{BOUND}}).
287
288
289==== number-hash
290
291 [procedure] (number-hash NUMBER [BOUND])
292
293For use with {{=}} as a {{hash-table-equivalence-function}}.
294
295
296==== object-uid-hash
297
298 [procedure] (object-uid-hash OBJECT [BOUND])
299
300Currently a synonym for {{equal?-hash}}.
301
302
303==== symbol-hash
304
305 [procedure] (symbol-hash SYMBOL [BOUND])
306
307For use with {{eq?}} as a {{hash-table-equivalence-function}}.
308
309
310==== keyword-hash
311
312 [procedure] (keyword-hash KEYWORD [BOUND])
313
314For use with {{eq?}} as a {{hash-table-equivalence-function}}.
315
316
317==== string-hash
318
319 [procedure] (string-hash STRING [BOUND])
320
321For use with {{string=?}} as a {{hash-table-equivalence-function}}.
322
323
324==== string-ci-hash
325
326 [procedure] (string-ci-hash STRING [BOUND])
327
328For use with {{string-ci=?}} as a {{hash-table-equivalence-function}}.
329
330
331==== eq?-hash
332
333 [procedure] (eq?-hash OBJECT [BOUND])
334
335For use with {{eq?}} as a {{hash-table-equivalence-function}}.
336
337
338==== eqv?-hash
339
340 [procedure] (eqv?-hash OBJECT [BOUND])
341
342For use with {{eqv?}} as a {{hash-table-equivalence-function}}.
343
344
345==== equal?-hash
346
347 [procedure] (equal?-hash OBJECT [BOUND])
348
349For use with {{equal?}} as a {{hash-table-equivalence-function}}.
350
351
352==== hash
353
354 [procedure] (hash OBJECT [BOUND])
355
356Synonym for {{equal?-hash}}.
357
358
359==== hash-by-identity
360
361 [procedure] (hash-by-identity OBJECT [BOUND])
362
363Synonym for {{eq?-hash}}.
364
365Previous: [[Unit srfi-18]]
366Next: [[Unit posix]]
367
Note: See TracBrowser for help on using the repository browser.