[279] | 1 | /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
|
---|
| 2 |
|
---|
| 3 | /* @(#) st.h 5.1 89/12/14 */
|
---|
| 4 |
|
---|
| 5 | #ifndef ST_INCLUDED
|
---|
| 6 |
|
---|
| 7 | #define ST_INCLUDED
|
---|
| 8 |
|
---|
| 9 | typedef uintptr_t st_data_t;
|
---|
| 10 | #define ST_DATA_T_DEFINED
|
---|
| 11 |
|
---|
| 12 | typedef struct st_table st_table;
|
---|
| 13 | typedef int st_index_t;
|
---|
| 14 |
|
---|
| 15 | struct st_hash_type {
|
---|
| 16 | int (*compare)();
|
---|
| 17 | int (*hash)();
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | struct st_table {
|
---|
| 21 | struct st_hash_type *type;
|
---|
| 22 | int num_bins;
|
---|
| 23 | int num_entries;
|
---|
| 24 | struct st_table_entry **bins;
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0)
|
---|
| 28 |
|
---|
| 29 | enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
|
---|
| 30 |
|
---|
| 31 | #ifndef _
|
---|
| 32 | # define _(args) args
|
---|
| 33 | #endif
|
---|
| 34 | #ifndef ANYARGS
|
---|
| 35 | # ifdef __cplusplus
|
---|
| 36 | # define ANYARGS ...
|
---|
| 37 | # else
|
---|
| 38 | # define ANYARGS
|
---|
| 39 | # endif
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | st_table *st_init_table _((struct st_hash_type *));
|
---|
| 43 | st_table *st_init_table_with_size _((struct st_hash_type *, int));
|
---|
| 44 | st_table *st_init_numtable _((void));
|
---|
| 45 | st_table *st_init_numtable_with_size _((int));
|
---|
| 46 | st_table *st_init_strtable _((void));
|
---|
| 47 | st_table *st_init_strtable_with_size _((int));
|
---|
| 48 | int st_delete _((st_table *, st_data_t *, st_data_t *));
|
---|
| 49 | int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t));
|
---|
| 50 | int st_insert _((st_table *, st_data_t, st_data_t));
|
---|
| 51 | int st_lookup _((st_table *, st_data_t, st_data_t *));
|
---|
| 52 | int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t));
|
---|
| 53 | void st_add_direct _((st_table *, st_data_t, st_data_t));
|
---|
| 54 | void st_free_table _((st_table *));
|
---|
| 55 | void st_cleanup_safe _((st_table *, st_data_t));
|
---|
| 56 | st_table *st_copy _((st_table *));
|
---|
| 57 |
|
---|
| 58 | #define ST_NUMCMP ((int (*)()) 0)
|
---|
| 59 | #define ST_NUMHASH ((int (*)()) -2)
|
---|
| 60 |
|
---|
| 61 | #define st_numcmp ST_NUMCMP
|
---|
| 62 | #define st_numhash ST_NUMHASH
|
---|
| 63 |
|
---|
| 64 | #endif /* ST_INCLUDED */
|
---|