Hash Table Type

Hash tables are arbitrary value indexed collections of references to values. The only value you cannot use as an index is #n.

Reader Form

Hash tables of simple key and value types can be constructed with the reader form

#{ [(key & value) ...] }

degenerating to #{}.

Any key or value will not be evaluated, only simple type construction (numbers, strings, symbols etc.) will occur.

This reader form ultimately calls alist->hash meaning the equivalence function will be the C implementation of equal? and the hashing function will be the default C implementation.

Hash Table Predicates

function hash? o

test if o is an hash

Param o:

object to test

Return:

#t if o is an hash, #f otherwise

Rtype:

boolean

Hash Table Constructors

function make-hash [ equiv-func [ hash-func [size]]]

create a hash table

Param equiv-func:

defaults to equal?

Type equiv-func:

function or symbol, optional

Param hash-func:

defaults to hash-table-hash

Type hash-func:

function, optional

Param size:

defaults to 32

Type size:

fixnum, optional

Return:

hash table

Rtype:

hash table

If either of hash-func or equiv-func is #n use the default.

As an accelerator if equiv-comp is one of the symbols 'eq?, 'eqv? or 'equal? then use the underlying C function.

function alist->hash al [args]

convert association list al into a hash table

Param al:

association list

Type al:

association list

Param args:

arguments for make-hash

Type args:

list, optional

Return:

hash table

Rtype:

hash table

alist->hash will use equal? as its equivalence function and the default hashing function

See also

make-hash

function copy-hash orig [depth]

copy hash table orig

Param orig:

initial hash table

Type orig:

hash table

Param depth:

'shallow or 'deep (default)

Type depth:

symbol, optional

Return:

the new hash table

Rtype:

hash table

function merge-hash! ht1 ht2

merge the key/value pairs in hash table ht2 into hash table ht1

duplicate keys in ht2 will overwrite keys in ht1

Param ht1:

hash table

Type ht1:

hash table

Param ht2:

hash table

Type ht2:

hash table

Return:

ht1

Rtype:

hash table

Hash Table Attributes

function hash-size h

return the key count of h

Param h:

hash table

Type h:

hash table

Return:

key count

Rtype:

integer

function hash-equivalence-function h

return the equiv-func of h

Param h:

hash table

Type h:

hash table

Return:

equivalence function

Rtype:

function or symbol (eq?, eqv? or equal?)

function hash-hash-function h

return the hash-func of h

Param h:

hash table

Type h:

hash table

Return:

hashing function

Rtype:

function or #n if using the default

function hash-ref ht key [default]

return the value indexed by key in hash table ht

Param ht:

hash table

Type ht:

hash table

Param key:

non-#n value

Type key:

any non-#n

Param default:

a default value if key not found

Type default:

a thunk or a simple value, optional

Return:

value

Rtype:

any

Raises ^rt-hash-key-not-found-error:

if key not found and no default supplied

function hash-set! ht key v

set the index of key in hash table ht to v

Param ht:

hash table

Type ht:

hash table

Param key:

non-#n value

Type key:

any non-#n

Param v:

value

Type v:

any

Return:

#<unspec>

function hash-delete! ht key

delete the value associated with index of key in hash table ht

Param ht:

hash table

Type ht:

hash table

Param key:

non-#n value

Type key:

any non-#n

Return:

#<unspec>

Hash Table Functions

function hash-exists? ht key

assert whether index of key in hash table ht exists

Param ht:

hash table

Type ht:

hash table

Param key:

non-#n value

Type key:

any non-#n

Return:

#t or #f

Rtype:

boolean

function hash-update! ht key func [default]

update the value indexed by key in hash table ht

SRFI-69:

Semantically equivalent to, but may be implemented more efficiently than, the following code:

hash-set! ht key (func (hash-ref ht key [default])))

That is, call func on the existing value and set the key to the returned value

Param ht:

hash table

Type ht:

hash table

Param key:

non-#n value

Type key:

any non-#n

Param func:

func to generate replacement value

Type func:

1-ary function

Param default:

see hash-ref

Type default:

see hash-ref

Return:

#<unspec>

See also

hash-ref

function hash-keys ht

return a list of the keys of the hash table ht

no order can be presumed

Param ht:

hash table

Type ht:

hash table

Return:

list of keys

Rtype:

list

function hash-values ht

return a list of the values of the hash table ht

no order can be presumed

Param ht:

hash table

Type ht:

hash table

Return:

list of values

Rtype:

list

function hash-walk ht func

call func for each key in hash table ht

Param ht:

hash table

Type ht:

hash table

Param func:

func to be called with each key, value pair

Type func:

2-ary function

Return:

#<unspec>

function fold-hash ht func val

call func for each key in hash table ht with arguments: key, the value indexed by key and val

val is updated to the value returned by func

The final value of val is returned

Param ht:

hash table

Type ht:

hash table

Param func:

func to be called with each key, value, val tuple

Type func:

3-ary function

Param val:

initial value for val

Type val:

any

Return:

final value of val

Rtype:

any

Last built at 2024-05-17T06:10:55Z+0000 from 62cca4c (dev) for Idio 0.3.b.6