From 1c2ee06db21df8983d546c9bbf2ddb21e7297fec Mon Sep 17 00:00:00 2001 From: Christopher Wellons Date: Fri, 7 Jan 2011 12:41:37 -0500 Subject: [PATCH] Adjust hashtable namespace to avoid conflicts with Wisp. --- gc.c | 6 +++--- hashtab.c | 38 +++++++++++++++++++------------------- hashtab.h | 20 ++++++++++---------- types.c | 12 ++++++------ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/gc.c b/gc.c index c421eab..9c124df 100644 --- a/gc.c +++ b/gc.c @@ -169,11 +169,11 @@ void mark_reachable(object * root) { mark_reachable(CIENV(root)); break; case HASH_TABLE: - ht_iter_init(HTAB(root), &htab_iter); + htb_iter_init(HTAB(root), &htab_iter); while(htab_iter.key != NULL) { mark_reachable((object *) htab_iter.key); mark_reachable((object *) htab_iter.value); - ht_iter_inc(&htab_iter); + htb_iter_inc(&htab_iter); } default: break; @@ -200,7 +200,7 @@ long sweep_unmarked() { free(VARRAY(head)); break; case HASH_TABLE: - ht_destroy(HTAB(head)); + htb_destroy(HTAB(head)); default: break; } diff --git a/hashtab.c b/hashtab.c index be50d5f..eb9e160 100644 --- a/hashtab.c +++ b/hashtab.c @@ -29,7 +29,7 @@ void xfree(void *p) { free(p); } -hashtab_t *ht_init(size_t size, int (*hash_func) (void *, size_t)) { +hashtab_t *htb_init(size_t size, int (*hash_func) (void *, size_t)) { hashtab_t *new_ht = (hashtab_t *) xmalloc(sizeof(hashtab_t)); new_ht->arr = (hashtab_node_t **) xmalloc(sizeof(hashtab_node_t *) * size); new_ht->size = size; @@ -41,15 +41,15 @@ hashtab_t *ht_init(size_t size, int (*hash_func) (void *, size_t)) { new_ht->arr[i] = NULL; if(hash_func == NULL) - new_ht->hash_func = &ht_hash; + new_ht->hash_func = &htb_hash; else new_ht->hash_func = hash_func; return new_ht; } -void *ht_search(hashtab_t * hashtable, void *key) { - int index = ht_hash(key, hashtable->size); +void *htb_search(hashtab_t * hashtable, void *key) { + int index = htb_hash(key, hashtable->size); if(hashtable->arr[index] == NULL) return NULL; @@ -62,8 +62,8 @@ void *ht_search(hashtab_t * hashtable, void *key) { return NULL; } -void *ht_insert(hashtab_t * hashtable, void *key, void *value) { - int index = ht_hash(key, hashtable->size); +void *htb_insert(hashtab_t * hashtable, void *key, void *value) { + int index = htb_hash(key, hashtable->size); hashtab_node_t *next_node, *last_node; next_node = hashtable->arr[index]; @@ -97,9 +97,9 @@ void *ht_insert(hashtab_t * hashtable, void *key, void *value) { } /* delete the given key from the hashtable */ -void ht_remove(hashtab_t * hashtable, void *key) { +void htb_remove(hashtab_t * hashtable, void *key) { hashtab_node_t *last_node, *next_node; - int index = ht_hash(key, hashtable->size); + int index = htb_hash(key, hashtable->size); next_node = hashtable->arr[index]; last_node = NULL; @@ -121,26 +121,26 @@ void ht_remove(hashtab_t * hashtable, void *key) { } /* grow the hashtable */ -hashtab_t *ht_grow(hashtab_t * old_ht, size_t new_size) { +hashtab_t *htb_grow(hashtab_t * old_ht, size_t new_size) { /* create new hashtable */ - hashtab_t *new_ht = ht_init(new_size, old_ht->hash_func); + hashtab_t *new_ht = htb_init(new_size, old_ht->hash_func); if(new_ht == NULL) return NULL; /* Iterate through the old hashtable. */ hashtab_iter_t ii; - ht_iter_init(old_ht, &ii); - for(; ii.key != NULL; ht_iter_inc(&ii)) - ht_insert(new_ht, ii.key, ii.value); + htb_iter_init(old_ht, &ii); + for(; ii.key != NULL; htb_iter_inc(&ii)) + htb_insert(new_ht, ii.key, ii.value); /* Destroy the old hashtable. */ - ht_destroy(old_ht); + htb_destroy(old_ht); return new_ht; } /* free all resources used by the hashtable */ -void ht_destroy(hashtab_t * hashtable) { +void htb_destroy(hashtab_t * hashtable) { hashtab_node_t *next_node, *last_node; /* Free each linked list in hashtable. */ @@ -160,18 +160,18 @@ void ht_destroy(hashtab_t * hashtable) { } /* iterator initilaize */ -void ht_iter_init(hashtab_t * hashtable, hashtab_iter_t * ii) { +void htb_iter_init(hashtab_t * hashtable, hashtab_iter_t * ii) { /* stick in initial bookeeping data */ ii->internal.hashtable = hashtable; ii->internal.node = NULL; ii->internal.index = -1; /* have iterator point to first element */ - ht_iter_inc(ii); + htb_iter_inc(ii); } /* iterator increment */ -void ht_iter_inc(hashtab_iter_t * ii) { +void htb_iter_inc(hashtab_iter_t * ii) { hashtab_t *hashtable = ii->internal.hashtable; int index = ii->internal.index; @@ -207,7 +207,7 @@ void ht_iter_inc(hashtab_iter_t * ii) { ii->value = ii->internal.node->value; } -int ht_hash(void *key, size_t hashtab_size) { +int htb_hash(void *key, size_t hashtab_size) { /* One-at-a-time hash */ uint32_t hash, i; for(hash = 0, i = 0; i < sizeof(key); ++i) { diff --git a/hashtab.h b/hashtab.h index d61ee1c..b8ed10f 100644 --- a/hashtab.h +++ b/hashtab.h @@ -49,22 +49,22 @@ typedef struct hashtab_iter_t * function pointer is given (a NULL pointer), then the built in hash * function is used. A NULL pointer returned if the creation of the * hashtable failed due to a failed malloc(). */ -hashtab_t *ht_init (size_t size, +hashtab_t *htb_init (size_t size, int (*hash_func) - (void *key, size_t ht_size)); + (void *key, size_t htb_size)); /* Fetch a value from table matching the key. Returns a pointer to * the value matching the given key. */ -void *ht_search (hashtab_t * hashtable, void *key); +void *htb_search (hashtab_t * hashtable, void *key); /* Put a value into the table with the given key. Returns NULL if * malloc() fails to allocate memory for the new node. */ -void *ht_insert (hashtab_t * hashtable, +void *htb_insert (hashtab_t * hashtable, void *key, void *value); /* Delete the given key and value pair from the hashtable. If the key * does not exist, no error is given. */ -void ht_remove (hashtab_t * hashtable, void *key); +void htb_remove (hashtab_t * hashtable, void *key); /* Change the size of the hashtable. It will allocate a new hashtable * and move all keys and values over. The pointer to the new hashtable @@ -72,21 +72,21 @@ void ht_remove (hashtab_t * hashtable, void *key); * allocated. If this happens, the old hashtable will not be altered * in any way. The old hashtable is destroyed upon a successful * grow. */ -hashtab_t *ht_grow (hashtab_t * hashtable, size_t new_size); +hashtab_t *htb_grow (hashtab_t * hashtable, size_t new_size); /* Free all resources used by the hashtable. */ -void ht_destroy (hashtab_t * hashtable); +void htb_destroy (hashtab_t * hashtable); /* Initialize the given iterator. It will point to the first element * in the hashtable. */ -void ht_iter_init (hashtab_t * hashtable, hashtab_iter_t * ii); +void htb_iter_init (hashtab_t * hashtable, hashtab_iter_t * ii); /* Increment the iterator to the next element. The iterator key and * value will point to NULL values when the iterator has reached the * end of the hashtable. */ -void ht_iter_inc (hashtab_iter_t * ii); +void htb_iter_inc (hashtab_iter_t * ii); /* Default hashtable hash function. */ -int ht_hash (void *key, size_t hashtab_size); +int htb_hash (void *key, size_t hashtab_size); #endif diff --git a/types.c b/types.c index 23a0a19..34d956a 100644 --- a/types.c +++ b/types.c @@ -182,7 +182,7 @@ object *list_to_vector(object * list) { object *make_hashtab(long size) { object *obj = alloc_object(); obj->type = HASH_TABLE; - HTAB(obj) = ht_init(size, NULL); + HTAB(obj) = htb_init(size, NULL); return obj; } @@ -191,15 +191,15 @@ char is_hashtab(object * obj) { } void set_hashtab(object * tab, object * key, object * val) { - ht_insert(HTAB(tab), key, val); + htb_insert(HTAB(tab), key, val); } void remkey_hashtab(object * tab, object * key) { - ht_remove(HTAB(tab), key); + htb_remove(HTAB(tab), key); } object *get_hashtab(object * tab, object * key, object * fail) { - object *val = ht_search(HTAB(tab), key); + object *val = htb_search(HTAB(tab), key); if(val == NULL) { return fail; } @@ -213,10 +213,10 @@ object *get_hashtab_keys(object * table) { push_root(&result); hashtab_iter_t iter; - ht_iter_init(HTAB(table), &iter); + htb_iter_init(HTAB(table), &iter); while(iter.key != NULL) { result = cons((object *) iter.key, result); - ht_iter_inc(&iter); + htb_iter_inc(&iter); } pop_root(&result); return result;