Changeset 9846 in project


Ignore:
Timestamp:
03/17/08 19:24:53 (12 years ago)
Author:
Kon Lovett
Message:

Put the hash stuff back.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chicken/trunk/manual/Unit extras

    r9587 r9846  
    44== Unit extras
    55
    6 This unit contains a collection of useful utility definitions. 
     6This unit contains a collection of useful utility definitions.
    77This unit is used by default, unless the program
    88is compiled with the {{-explicit-use}} option.
     9
    910
    1011
     
    6768(chop '(a b c d) 3)     ==> ((a b c) (d))
    6869</enscript>
    69 
    7070
    7171
     
    230230=== Hash tables
    231231
    232 CHICKEN implements SRFI-69. For more information,
    233 see [[http://srfi.schemers.org/srfi-69/srfi-69.html|SRFI-69]].
     232CHICKEN implements SRFI 69 with SRFI 90 extensions. For more information, see
     233[[http://srfi.schemers.org/srfi-69/srfi-69.html|SRFI-69]] and
     234[[http://srfi.schemers.org/srfi-90/srfi-90.html|SRFI-90]].
     235
     236
     237==== make-hash-table
     238
     239 [procedure] (make-hash-table [TEST HASH SIZE] #:TEST #:HASH #:SIZE #:INITIAL #:MIN-LOAD #:MAX-LOAD #:WEAK-KEYS #:WEAK-VALUES)
     240
     241Returns a new {{HASH-TABLE}} with the supplied configuration.
     242
     243; {{TEST}} : The equivalence function.
     244; {{HASH}} : The hash function.
     245; {{SIZE}} : The expected number of table elements.
     246; {{INITIAL}} : The default initial value.
     247; {{MIN-LOAD}} : The minimum load factor. A {{flonum}} in (0.0 1.0).
     248; {{MAX-LOAD}} : The maximum load factor. A {{flonum}} in (0.0 1.0).
     249; {{WEAK-KEYS}} : Use weak references for keys. (Ignored)
     250; {{WEAK-VALUES}} : Use weak references for values. (Ignored)
     251
     252(No, the keyword parameters are not uppercase.)
     253
     254
     255==== hash-table?
     256
     257 [procedure] (hash-table? OBJECT)
     258
     259Is the {{OBJECT}} a {{hash-table}}?
     260
     261
     262==== hash-table-size
     263
     264 [procedure] (hash-table-size HASH-TABLE)
     265
     266The {{HASH-TABLE}} size.
     267
     268
     269==== hash-table-equivalence-function
     270
     271 [procedure] (hash-table-equivalence-function HASH-TABLE)
     272
     273The {{HASH-TABLE}} {{equivalence-function}}.
     274
     275
     276==== hash-table-hash-function
     277
     278 [procedure] (hash-table-hash-function HASH-TABLE)
     279
     280The {{HASH-TABLE}} {{hash-function}}.
     281
     282
     283==== hash-table-min-load
     284
     285 [procedure] (hash-table-min-load HASH-TABLE)
     286
     287The {{HASH-TABLE}} minimum load factor.
     288
     289
     290==== hash-table-max-load
     291
     292 [procedure] (hash-table-max-load HASH-TABLE)
     293
     294The {{HASH-TABLE}} maximum load factor.
     295
     296
     297==== hash-table-weak-keys
     298
     299 [procedure] (hash-table-weak-keys HASH-TABLE)
     300
     301Does the {{HASH-TABLE}} weak references for keys?
     302
     303
     304==== hash-table-weak-values
     305
     306 [procedure] (hash-table-weak-values HASH-TABLE)
     307
     308Does the {{HASH-TABLE}} weak references for values?
     309
     310
     311==== hash-table-has-initial?
     312
     313 [procedure] (hash-table-has-initial? HASH-TABLE)
     314
     315Does the {{HASH-TABLE}} have a default initial value?
     316
     317
     318==== hash-table-initial
     319
     320 [procedure] (hash-table-initial HASH-TABLE)
     321
     322The {{HASH-TABLE}} default initial value.
     323
     324
     325==== hash-table-keys
     326
     327 [procedure] (hash-table-keys HASH-TABLE)
     328
     329Returns a list of the keys in the {{HASH-TABLE}} population.
     330
     331
     332==== hash-table-values
     333
     334 [procedure] (hash-table-values HASH-TABLE)
     335
     336Returns a list of the values in the {{HASH-TABLE}} population.
     337
     338
     339==== hash-table->alist
     340
     341 [procedure] (hash-table->alist HASH-TABLE)
     342
     343Returns the population of the {{HASH-TABLE}} as an {{association-list}}.
     344
     345
     346==== alist->hash-table
     347
     348 [procedure] (alist->hash-table ASSOCIATION-LIST [MAKE-HASH-TABLE-PARAMETER ...])
     349
     350Returns a new {{HASH-TABLE}}, configured using the optional
     351{{MAKE-HASH-TABLE-PARAMETER ...}}. The {{HASH-TABLE}} is populated from the
     352{{ASSOCIATION-LIST}}.
     353
     354
     355==== hash-table-ref
     356
     357 [procedure] (hash-table-ref HASH-TABLE KEY)
     358
     359Returns the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}.
     360
     361Aborts with an exception when the {{KEY}} is missing.
     362
     363
     364==== hash-table-ref/default
     365
     366 [procedure] (hash-table-ref/default HASH-TABLE KEY DEFAULT)
     367
     368Returns the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}, or the {{DEFAULT}}
     369when the {{KEY}} is missing.
     370
     371
     372==== hash-table-exists?
     373
     374 [procedure] (hash-table-exists? HASH-TABLE KEY)
     375
     376Does the {{KEY}} exist in the {{HASH-TABLE}}?
     377
     378
     379==== hash-table-set!
     380
     381 [procedure] (hash-table-set! HASH-TABLE KEY VALUE)
     382
     383Set the {{VALUE}} for the {{KEY}} in the {{HASH-TABLE}}.
    234384
    235385A setter for {{hash-table-ref}} is defined, so
    236386
    237387<enscript highlight=scheme>
    238 (set! (hash-table-ref HT KEY) VAL)
     388(set! (hash-table-ref HASH-TABLE KEY) VALUE)
    239389</enscript>
    240390
     
    242392
    243393<enscript highlight=scheme>
    244 (hash-table-set! HT KEY VAL)
    245 </enscript>
    246 
    247 As an extension to SRFI-69, {{hash-table-update!}} and {{hash-table-update!/default}} return
    248 the new value (after applying the update procedure).
     394(hash-table-set! HASH-TABLE KEY VALUE)
     395</enscript>
     396
     397
     398==== hash-table-update!
     399
     400 [procedure] (hash-table-update! HASH-TABLE KEY [UPDATE-FUNCTION [DEFAULT-VALUE-FUNCTION]])
     401
     402Sets or replaces the {{VALUE}} for {{KEY}} in the {{HASH-TABLE}}.
     403
     404The {{UPDATE-FUNCTION}} takes the existing {{VALUE}} for {{KEY}} and returns
     405the new {{VALUE}}. The default is {{identity}}
     406
     407The {{DEFAULT-VALUE-FUNCTION}} is called when the entry for {{KEY}} is missing.
     408The default uses the {{(hash-table-initial-value)}}, if provided. Otherwise
     409aborts with an exception.
     410
     411Returns the new {{VALUE}}.
     412
     413
     414==== hash-table-update!/default
     415
     416 [procedure] (hash-table-update! HASH-TABLE KEY UPDATE-FUNCTION DEFAULT-VALUE)
     417
     418Sets or replaces the {{VALUE}} for {{KEY}} in the {{HASH-TABLE}}.
     419
     420The {{UPDATE-FUNCTION}} takes the existing {{VALUE}} for {{KEY}} and returns
     421the new {{VALUE}}.
     422
     423The {{DEFAULT-VALUE}} is used when the entry for {{KEY}} is missing.
     424
     425Returns the new {{VALUE}}.
     426
     427
     428==== hash-table-copy
     429
     430 [procededure] (hash-table-copy HASH-TABLE)
     431
     432Returns a shallow copy of the {{HASH-TABLE}}.
     433
     434
     435==== hash-table-delete!
     436
     437 [procedure] (hash-table-delete! HASH-TABLE KEY)
     438
     439Deletes the entry for {{KEY}} in the {{HASH-TABLE}}.
     440
    249441
    250442==== hash-table-remove!
    251443
    252  [procedure] (hash-table-remove! HASHTABLE PROC)
    253 
    254 Calls {{PROC}} for all entries in {{HASHTABLE}} with the key and value of each
     444 [procedure] (hash-table-remove! HASH-TABLE PROC)
     445
     446Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
    255447entry. If {{PROC}} returns true, then that entry is removed.
     448
     449
     450==== hash-table-merge
     451
     452 [procedure] (hash-table-merge HASH-TABLE-1 HASH-TABLE-2)
     453
     454Returns a new {{HASH-TABLE}} with the union of {{HASH-TABLE-1}} and
     455{{HASH-TABLE-2}}.
     456
     457
     458==== hash-table-merge!
     459
     460 [procedure] (hash-table-merge! HASH-TABLE-1 HASH-TABLE-2)
     461
     462Returns {{HASH-TABLE-1}} as the union of {{HASH-TABLE-1}} and
     463{{HASH-TABLE-2}}.
     464
     465
     466==== hash-table-map
     467
     468 [procedure] (hash-table-map HASH-TABLE FUNC)
     469
     470Calls {{FUNC}} for all entries in {{HASH-TABLE}} with the key and value of each
     471entry.
     472
     473Returns a list of the results of each call.
     474
     475
     476==== hash-table-fold
     477
     478 [procedure] (hash-table-fold HASH-TABLE FUNC INIT)
     479
     480Calls {{FUNC}} for all entries in {{HASH-TABLE}} with the key and value of each
     481entry, and the current folded value. The initial folded value is {{INIT}}.
     482
     483Returns the final folded value.
     484
     485
     486==== hash-table-for-each
     487
     488 [procedure] (hash-table-for-each HASH-TABLE PROC)
     489
     490Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
     491entry.
     492
     493
     494==== hash-table-walk
     495
     496 [procedure] (hash-table-walk HASH-TABLE PROC)
     497
     498Calls {{PROC}} for all entries in {{HASH-TABLE}} with the key and value of each
     499entry.
     500
     501
     502=== Hash Functions
     503
     504All hash functions return a {{fixnum}} in the range [0 {{BOUND}}).
     505
     506
     507==== number-hash
     508
     509 [procedure] (number-hash NUMBER [BOUND])
     510
     511For use with {{=}} as a {{hash-table-equivalence-function}}.
     512
     513
     514==== object-uid-hash
     515
     516 [procedure] (object-uid-hash OBJECT [BOUND])
     517
     518Currently a synonym for {{equal?-hash}}.
     519
     520
     521==== symbol-hash
     522
     523 [procedure] (symbol-hash SYMBOL [BOUND])
     524
     525For use with {{eq?}} as a {{hash-table-equivalence-function}}.
     526
     527
     528==== keyword-hash
     529
     530 [procedure] (keyword-hash KEYWORD [BOUND])
     531
     532For use with {{eq?}} as a {{hash-table-equivalence-function}}.
     533
     534
     535==== string-hash
     536
     537 [procedure] (string-hash STRING [BOUND])
     538
     539For use with {{string=?}} as a {{hash-table-equivalence-function}}.
     540
     541
     542==== string-ci-hash
     543
     544 [procedure] (string-ci-hash STRING [BOUND])
     545
     546For use with {{string-ci=?}} as a {{hash-table-equivalence-function}}.
     547
     548
     549==== eq?-hash
     550
     551 [procedure] (eq?-hash OBJECT [BOUND])
     552
     553For use with {{eq?}} as a {{hash-table-equivalence-function}}.
     554
     555
     556==== eqv?-hash
     557
     558 [procedure] (eqv?-hash OBJECT [BOUND])
     559
     560For use with {{eqv?}} as a {{hash-table-equivalence-function}}.
     561
     562
     563==== equal?-hash
     564
     565 [procedure] (equal?-hash OBJECT [BOUND])
     566
     567For use with {{equal?}} as a {{hash-table-equivalence-function}}.
     568
     569
     570==== hash
     571
     572 [procedure] (hash OBJECT [BOUND])
     573
     574Synonym for {{equal?-hash}}.
     575
     576
     577==== hash-by-identity
     578
     579 [procedure] (hash-by-identity OBJECT [BOUND])
     580
     581Synonym for {{eq?-hash}}.
    256582
    257583
     
    386712 [procedure] (random-seed [SEED])
    387713
    388 Seeds the random number generator with {{SEED}} (an exact integer) or 
     714Seeds the random number generator with {{SEED}} (an exact integer) or
    389715{{(current-seconds)}} if {{SEED}} is not given.
    390716
     
    470796input is read from the port that is the current value of {{(current-input-port)}}.
    471797After all expressions are read, and if the argument is a port, then the port will
    472 not be closed. The {{READER}} argument specifies the procedure used to read 
     798not be closed. The {{READER}} argument specifies the procedure used to read
    473799expressions from the given file or port and defaults to {{read}}. The reader
    474800procedure will be called with a single argument (an input port).
     
    507833
    508834Read or write {{NUM}} characters from/to {{PORT}}, which defaults to the
    509 value of {{(current-input-port)}} or {{(current-output-port)}}, respectively. 
     835value of {{(current-input-port)}} or {{(current-output-port)}}, respectively.
    510836If {{NUM}} is {{#f}} or not given, then all data
    511837up to the end-of-file is read, or, in the case of {{write-string}} the whole
     
    631957
    632958Split string into substrings separated by the given delimiters. If
    633 no delimiters are specified, a string comprising the tab, newline and space characters 
     959no delimiters are specified, a string comprising the tab, newline and space characters
    634960is assumed. If the
    635961parameter {{KEEPEMPTY}} is given and not {{#f}}, then empty
     
    8041130
    8051131<enscript highlight=scheme>
    806 (lambda args 
     1132(lambda args
    8071133  (apply pp args)
    8081134  (apply eval args) )
Note: See TracChangeset for help on using the changeset viewer.