Hashtables
[Functional objects]

Collaboration diagram for Hashtables:

A functional hash table is a function from symbols or integers to arbitrary values. More...

Data Structures

struct  hashtable_t
struct  _defs

Functions

static void hashtable_init (void *p, muse_cell args)
static void hashtable_mark (void *p)
static void hashtable_destroy (void *p)
static void hashtable_write (void *ptr, void *port)
 Writes the hashtable out to the given port in the form.
static int bucket_for_hash (muse_int hash, int modulus)
static void hashtable_rehash (hashtable_t *h, int new_bucket_count)
muse_cell fn_hashtable_stats (muse_env *env, void *context, muse_cell args)
static muse_cellhashtable_add (hashtable_t *h, muse_cell key, muse_cell value, muse_int *hash_opt)
static muse_cellhashtable_get (hashtable_t *h, muse_cell key, muse_int *hash_out)
muse_cell fn_hashtable (muse_env *env, hashtable_t *h, muse_cell args)
static muse_cell hashtable_size (void *self)
static void hashtable_merge_one (hashtable_t *h1, muse_cell key, muse_cell new_value, muse_cell reduction_fn)
static muse_cell hashtable_map (void *self, muse_cell fn)
static void hashtable_merge (hashtable_t *h1, hashtable_t *h2, muse_cell reduction_fn)
static muse_cell hashtable_join (void *self, muse_cell objlist, muse_cell reduction_fn)
static muse_cell hashtable_collect (void *self, muse_cell predicate, muse_cell mapper, muse_cell reduction_fn)
static muse_cell hashtable_reduce (void *self, muse_cell reduction_fn, muse_cell initial)
static void * hashtable_view (int id)
muse_cell fn_mk_hashtable (muse_env *env, void *context, muse_cell args)
 (mk-hashtable [size]).
muse_cell fn_hashtable_p (muse_env *env, void *context, muse_cell args)
 (hashtable? ht).
muse_cell fn_hashtable_size (muse_env *env, void *context, muse_cell args)
 (hashtable-size ht).
muse_cell fn_alist_to_hashtable (muse_env *env, void *context, muse_cell args)
 (hashtable alist).
muse_cell fn_hashtable_to_alist (muse_env *env, void *context, muse_cell args)
 (hashtable->alist ht).
void muse_define_builtin_type_hashtable ()
muse_cell muse_mk_hashtable (int length)
 Creates a hashtable with a bucket count setup according to the given desired length.
int muse_hashtable_length (muse_cell ht)
 Returns the number of key-value pairs put into the hash table.
muse_cell muse_hashtable_get (muse_cell ht, muse_cell key)
 Returns the key-value pair with the given key as the head if the key is present in the hash table, otherwise it returns MUSE_NIL.
muse_cell muse_hashtable_put (muse_cell ht, muse_cell key, muse_cell value)
 Associates the given value with the given key in the hash table.

Variables

static muse_monad_view_t g_hashtable_monad_view
static muse_functional_object_type_t g_hashtable_type
static struct _defs k_hashtable_funs []

Detailed Description

A functional hash table is a function from symbols or integers to arbitrary values.

When given only a single key argument, it returns the value associated with the key. If no value is associated with the key, it returns (). Note that this means you can't distinguish between a key being associated with a () value and the key not being present in the hash table.

When given two arguments key and value, adds the association to the hash table and returns the value. If you want to remove a key's association from the hash table, pass a second argument of ().

Examples -

 (define ht (mk-hashtable))
 (ht 'ceo 'pete)
 (ht 'coo 'terence)
 (ht 'company 'muvee)
 (print (ht 'ceo))
      > pete
 (print (hashtable-size ht))
      > 3
 (print (hashtable->alist ht))
      > ((coo . terence) (ceo . pete) (company . muvee))
 (ht 'company ())
 (print (hashtable-size ht))
      > 2
 (print (hashtable->alist ht))
      > ((coo . terence) (ceo . pete))

Function Documentation

static void hashtable_init ( void *  p,
muse_cell  args 
) [static]

static void hashtable_mark ( void *  p  )  [static]

static void hashtable_destroy ( void *  p  )  [static]

static void hashtable_write ( void *  ptr,
void *  port 
) [static]

Writes the hashtable out to the given port in the form.

    {hashtable '((key1 . value1) (key2 . value2) ... (keyN . valueN))}
Since it uses braces, a trusted read operation will automatically give the hashtable object in the position that this expression is inserted.

static int bucket_for_hash ( muse_int  hash,
int  modulus 
) [static]

static void hashtable_rehash ( hashtable_t h,
int  new_bucket_count 
) [static]

muse_cell fn_hashtable_stats ( muse_env env,
void *  context,
muse_cell  args 
)

static muse_cell* hashtable_add ( hashtable_t h,
muse_cell  key,
muse_cell  value,
muse_int hash_opt 
) [static]

static muse_cell* hashtable_get ( hashtable_t h,
muse_cell  key,
muse_int hash_out 
) [static]

muse_cell fn_hashtable ( muse_env env,
hashtable_t h,
muse_cell  args 
)

static muse_cell hashtable_size ( void *  self  )  [static]

static void hashtable_merge_one ( hashtable_t h1,
muse_cell  key,
muse_cell  new_value,
muse_cell  reduction_fn 
) [static]

static muse_cell hashtable_map ( void *  self,
muse_cell  fn 
) [static]

static void hashtable_merge ( hashtable_t h1,
hashtable_t h2,
muse_cell  reduction_fn 
) [static]

static muse_cell hashtable_join ( void *  self,
muse_cell  objlist,
muse_cell  reduction_fn 
) [static]

static muse_cell hashtable_collect ( void *  self,
muse_cell  predicate,
muse_cell  mapper,
muse_cell  reduction_fn 
) [static]

static muse_cell hashtable_reduce ( void *  self,
muse_cell  reduction_fn,
muse_cell  initial 
) [static]

static void* hashtable_view ( int  id  )  [static]

muse_cell fn_mk_hashtable ( muse_env env,
void *  context,
muse_cell  args 
)

(mk-hashtable [size]).

Creates a new hash table. No arguments are required, but you can give the expected size of the hash table as an argument.

muse_cell fn_hashtable_p ( muse_env env,
void *  context,
muse_cell  args 
)

(hashtable? ht).

Returns ht if it is a functional hashtable, or () if it isn't.

muse_cell fn_hashtable_size ( muse_env env,
void *  context,
muse_cell  args 
)

(hashtable-size ht).

Returns the number of key-value pairs stored in the hash table.

muse_cell fn_alist_to_hashtable ( muse_env env,
void *  context,
muse_cell  args 
)

(hashtable alist).

Returns a hash table with the same contents as the given alist.

muse_cell fn_hashtable_to_alist ( muse_env env,
void *  context,
muse_cell  args 
)

(hashtable->alist ht).

Returns an alist version of the contents of the given hash table. The order of the elements is unpredictable.

void muse_define_builtin_type_hashtable (  ) 

muse_cell muse_mk_hashtable ( int  length  ) 

Creates a hashtable with a bucket count setup according to the given desired length.

Note that calling muse_hashtable_length() without first putting anything into the hashtable will always get you 0. The "length" of the hashtable is the number of key-value pairs put into it.

int muse_hashtable_length ( muse_cell  ht  ) 

Returns the number of key-value pairs put into the hash table.

muse_cell muse_hashtable_get ( muse_cell  ht,
muse_cell  key 
)

Returns the key-value pair with the given key as the head if the key is present in the hash table, otherwise it returns MUSE_NIL.

The value associated with the key will be in the tail of the returned pair.

muse_cell muse_hashtable_put ( muse_cell  ht,
muse_cell  key,
muse_cell  value 
)

Associates the given value with the given key in the hash table.

The given value replaces any previous value that might have been associated with the key.


Variable Documentation

muse_monad_view_t g_hashtable_monad_view [static]

Initial value:

muse_functional_object_type_t g_hashtable_type [static]

Initial value:

struct _defs k_hashtable_funs[] [static]


Generated on Mon Sep 25 23:12:49 2006 for muSE by  doxygen 1.4.7