diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-18 02:34:12 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-18 02:34:12 -0400 |
commit | 6ed8bef65e54efdb98841ef9b6eb3ea3c9be82d5 (patch) | |
tree | 18569e996f7f2f61de2285ffa54d7854478e132d /htable.h | |
parent | 9e0994d5a997a5b8c298992f05c94ba1b22a692c (diff) |
big progress on streaming in sync and controlling multiple users
Diffstat (limited to 'htable.h')
-rw-r--r-- | htable.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/htable.h b/htable.h new file mode 100644 index 0000000..65eac58 --- /dev/null +++ b/htable.h @@ -0,0 +1,45 @@ +#ifndef __HASHTABLE_H__ +#define __HASHTABLE_H__ + +#include <pthread.h> + +#include "list.h" + +/* FIXME make this a doubly-hashed, dynamically groweable hashtable */ + +typedef struct htable { + list_t *ht_hash; /* table entries */ + unsigned int ht_size; /* table size */ + unsigned int ht_cap; /* table capacity */ +} htable_t; + +typedef struct htable_node { + list_t hn_link; /* link */ + unsigned int hn_id; /* hash id */ + void *hn_data; /* data */ +} htable_node_t; + +void htable_init( htable_t *ht, unsigned int cap ); +void htable_destroy( htable_t *ht ); +void *htable_get( htable_t *ht, unsigned int id ); +void *htable_put( htable_t *ht, unsigned int id, void *data ); +void *htable_remove( htable_t *ht, unsigned int id ); + +#define htable_iterate_begin( ht, key, var, type ) \ +do { \ + unsigned int ___i; \ + htable_t *__ht = (ht); \ + htable_node_t *__hnode; \ + for(___i = 0;___i < __ht->ht_cap;___i++ ) { \ + list_iterate_begin( &__ht->ht_hash[___i ], __hnode, htable_node_t, hn_link ) { \ + (var) = (type*) __hnode->hn_data; \ + (key) = __hnode->hn_id; \ + do + +#define htable_iterate_end() \ + while( 0 ); \ + } list_iterate_end(); \ + } \ +} while( 0 ) + +#endif /* __HASHTABLE_H__ */
\ No newline at end of file |