1 /* $NetBSD: htable.h,v 1.2 2017/02/14 01:16:49 christos Exp $ */ 2 3 #ifndef _HTABLE_H_INCLUDED_ 4 #define _HTABLE_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* htable 3h 9 /* SUMMARY 10 /* hash table manager 11 /* SYNOPSIS 12 /* #include <htable.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* Structure of one hash table entry. */ 17 18 typedef struct HTABLE_INFO { 19 char *key; /* lookup key */ 20 void *value; /* associated value */ 21 struct HTABLE_INFO *next; /* colliding entry */ 22 struct HTABLE_INFO *prev; /* colliding entry */ 23 } HTABLE_INFO; 24 25 /* Structure of one hash table. */ 26 27 typedef struct HTABLE { 28 ssize_t size; /* length of entries array */ 29 ssize_t used; /* number of entries in table */ 30 HTABLE_INFO **data; /* entries array, auto-resized */ 31 HTABLE_INFO **seq_bucket; /* current sequence hash bucket */ 32 HTABLE_INFO **seq_element; /* current sequence element */ 33 } HTABLE; 34 35 extern HTABLE *htable_create(ssize_t); 36 extern HTABLE_INFO *htable_enter(HTABLE *, const char *, void *); 37 extern HTABLE_INFO *htable_locate(HTABLE *, const char *); 38 extern void *htable_find(HTABLE *, const char *); 39 extern void htable_delete(HTABLE *, const char *, void (*) (void *)); 40 extern void htable_free(HTABLE *, void (*) (void *)); 41 extern void htable_walk(HTABLE *, void (*) (HTABLE_INFO *, void *), void *); 42 extern HTABLE_INFO **htable_list(HTABLE *); 43 extern HTABLE_INFO *htable_sequence(HTABLE *, int); 44 45 #define HTABLE_SEQ_FIRST 0 46 #define HTABLE_SEQ_NEXT 1 47 #define HTABLE_SEQ_STOP (-1) 48 49 /* 50 * Correct only when casting (char *) to (void *). 51 */ 52 #define HTABLE_ACTION_FN_CAST(f) ((void *)(HTABLE_INFO *, void *)) (f) 53 #define HTABLE_FREE_FN_CAST(f) ((void *)(void *)) (f) 54 55 /* LICENSE 56 /* .ad 57 /* .fi 58 /* The Secure Mailer license must be distributed with this software. 59 /* AUTHOR(S) 60 /* Wietse Venema 61 /* IBM T.J. Watson Research 62 /* P.O. Box 704 63 /* Yorktown Heights, NY 10598, USA 64 /* CREATION DATE 65 /* Fri Feb 14 13:43:19 EST 1997 66 /* LAST MODIFICATION 67 /* %E% %U% 68 /* VERSION/RELEASE 69 /* %I% 70 /*--*/ 71 72 #endif 73