1 /* 2 Copyright (C) 2003 Cedric Cellier, Dominique Lavault 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 /* 19 * Functions to create and manipulate a hash. 20 * The key is an unsigned, the value a void*. 21 * 22 */ 23 24 #ifndef _GLTV_HASH_ 25 #define _GLTV_HASH_ 26 27 #define GLTV_HASH_OPT_SIZE 0x0 28 #define GLTV_HASH_OPT_SPEED 0x1 29 #define GLTV_HASH_STRKEYS 0x2 30 31 struct s_gltv_hash; 32 typedef struct s_gltv_hash* GLTV_HASH; 33 34 /* to get a new empty hash. 35 * nbr_of_total_elements is the expected total numbers of elements 36 * nbr_of_elements_per_line is an accepted hash collision per key (best case) 37 * if GLTV_HASH_OPT_SIZE the stack of remove entries is smaller 38 * if GLTV_HASH_OPT_SPEED the stack will expand as necessary 39 * if GLTV_HASH_STRKEYS the passed keys are, in fact, char* of strings... 40 * Beware, in this case, that you are responsible for keeping this pointer valid 41 * for the whole life of the hash. in a next version, the hash could register for this memory 42 * and release it when the entry is deleted... 43 */ 44 45 extern GLTV_HASH gltv_hash_new(unsigned, unsigned, int); 46 /* to delete a hash */ 47 extern void gltv_hash_del(GLTV_HASH); 48 /* to put a new pair of key/value or update the value associated with the key */ 49 /* Its not guaranted weither a given implementation would permit to convert a pointer to an int and back again to the same pointer. It MUST works, otherwise take long or whatever for holding keys */ 50 extern void gltv_hash_put(GLTV_HASH, unsigned, void *); 51 /* to get the value associated with a key (in value). return 0 if key does not exists */ 52 extern char gltv_hash_get(GLTV_HASH, unsigned, void **); 53 /* tells wether a key is defined in the hash */ 54 extern char gltv_hash_defined(GLTV_HASH, unsigned); 55 /* remove the value associated to the key */ 56 extern char gltv_hash_remove(GLTV_HASH, unsigned); 57 /* tells how many keys are defined */ 58 extern unsigned gltv_hash_size(GLTV_HASH); 59 /* reset the read pointer */ 60 extern void gltv_hash_reset(GLTV_HASH); 61 /* read next pair (key,value). return 0 if there are no more values */ 62 extern char gltv_hash_each(GLTV_HASH, unsigned *, void **); 63 /* once you are done inserting new key in the hash, you can compact it with 64 * the hash still works as a hash, anyway */ 65 extern void gltv_hash_compact(GLTV_HASH); 66 67 /* TODO : add a cursor to scan the hash without semaphore ? */ 68 69 #endif 70