1 /* $OpenBSD: hash.h,v 1.1 2008/06/21 15:39:15 joris Exp $ */ 2 /* 3 * Copyright (c) 2008 Joris Vink <joris@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* 19 * This is based upon: 20 * src/lib/libc/stdlib/hcreate.c 21 */ 22 23 #ifndef _H_HASH 24 #define _H_HASH 25 26 struct hash_data { 27 char *h_key; 28 void *h_data; 29 }; 30 31 struct hash_table_entry { 32 SLIST_ENTRY(hash_table_entry) h_list; 33 struct hash_data h_data; 34 }; 35 36 SLIST_HEAD(hash_head, hash_table_entry); 37 38 struct hash_table { 39 struct hash_head *h_table; 40 size_t h_size; 41 }; 42 43 #define MIN_HASH_SIZE (1 << 4) 44 #define MAX_HASH_SIZE ((size_t)1 << (sizeof(size_t) * 8 - 1 - 5)) 45 46 void hash_table_init(struct hash_table *, size_t); 47 void hash_table_enter(struct hash_table *, struct hash_data *); 48 struct hash_data *hash_table_find(struct hash_table *, const char *, size_t); 49 50 u_int32_t hash4(const char *, size_t); 51 52 extern struct hash_table created_directories; 53 extern struct hash_table created_cvs_directories; 54 55 #endif 56