/[guile]/guile/guile-core/doc/ref/scheme-compound.texi
ViewVC logotype

Diff of /guile/guile-core/doc/ref/scheme-compound.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by kryde, Sun Aug 17 00:28:51 2003 UTC revision 1.13 by kryde, Fri Aug 29 23:01:17 2003 UTC
# Line 2252  Like the association list functions, the Line 2252  Like the association list functions, the
2252  several varieties, according to the equality test used for the keys.  several varieties, according to the equality test used for the keys.
2253  Plain @code{hash-} functions use @code{equal?}, @code{hashq-}  Plain @code{hash-} functions use @code{equal?}, @code{hashq-}
2254  functions use @code{eq?}, @code{hashv-} functions use @code{eqv?}, and  functions use @code{eq?}, @code{hashv-} functions use @code{eqv?}, and
2255  the @code{hashx-} functions use an application supplied test (for  the @code{hashx-} functions use an application supplied test.
 instance to implement case insensitive strings).  
2256    
2257  A single @code{make-hash-table} creates a hash table suitable for use  A single @code{make-hash-table} creates a hash table suitable for use
2258  with any set of functions, but it's imperative that just one set is  with any set of functions, but it's imperative that just one set is
# Line 2266  bucket in case distinct keys hash togeth Line 2265  bucket in case distinct keys hash togeth
2265  pairs in those lists is provided by the @code{-handle-} functions.  pairs in those lists is provided by the @code{-handle-} functions.
2266    
2267  For the @code{hashx-} ``extended'' routines, an application supplies a  For the @code{hashx-} ``extended'' routines, an application supplies a
2268  @var{hash} function producing an integer index (like @code{hashq} etc  @var{hash} function producing an integer index like @code{hashq} etc
2269  below), and an @var{assoc} alist search function (like @code{assq}  below, and an @var{assoc} alist search function like @code{assq} etc
2270  etc, @xref{Retrieving Alist Entries}.).  The aim in the @var{hash}  (@pxref{Retrieving Alist Entries}).  Here's an example of such
2271  function is to have different keys spread out across the vector, so  functions implementing case-insensitive hashing of string keys,
2272  the bucket lists don't become long, but the exact values generated are  
2273  otherwise arbitrary.  @example
2274    (use-modules (srfi srfi-1)
2275                 (srfi srfi-13))
2276    (define (my-hash str size)
2277      (remainder (string-hash-ci str) size))
2278    (define (my-assoc str alist)
2279      (find (lambda (pair) (string-ci=? str (car pair))) alist))
2280    
2281    (define my-table (make-hash-table))
2282    (hashx-set! my-hash my-assoc my-table "foo" 123)
2283    
2284    (hashx-ref my-hash my-assoc my-table "FOO")
2285    @result{} 123
2286    @end example
2287    
2288    In a @code{hashx-} @var{hash} function the aim is to spread keys
2289    across the vector, so bucket lists don't become long, but the actual
2290    values are arbitrary (so long as they're in the range 0 to
2291    @math{@var{size}-1}).  Helpful functions for forming a hash value, in
2292    addition to @code{hashq} etc below, include @code{symbol-hash}
2293    (@pxref{Symbol Keys}), @code{string-hash} and @code{string-hash-ci}
2294    (@pxref{SRFI-13 Comparison}), and @code{char-set-hash} (@pxref{SRFI-14
2295    Predicates/Comparison}).
2296    
2297  @sp 1  @sp 1
2298  @deffn {Scheme Procedure} make-hash-table [size]  @deffn {Scheme Procedure} make-hash-table [size]
# Line 2380  pair. Line 2401  pair.
2401  Apply @var{proc} to the entries in the given hash @var{table}.  Each  Apply @var{proc} to the entries in the given hash @var{table}.  Each
2402  call is @code{(@var{proc} @var{key} @var{value})}.  @code{hash-map}  call is @code{(@var{proc} @var{key} @var{value})}.  @code{hash-map}
2403  returns a list of the results from these calls, @code{hash-for-each}  returns a list of the results from these calls, @code{hash-for-each}
2404  discards the results and returns unspecified value.  discards the results and returns an unspecified value.
2405    
2406  Calls are made over the table entries in an unspecified order, and for  Calls are made over the table entries in an unspecified order, and for
2407  @code{hash-map} the order of the values in the returned list is  @code{hash-map} the order of the values in the returned list is

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26