2 * Regular Pattern Analyzer (RPA)
3 * Copyright (c) 2009-2010 Martin Stoilov
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Martin Stoilov <martin@rpasearch.com>
25 #include "rlib/robject.h"
26 #include "rlib/rlist.h"
33 typedef struct rhash_node_s rhash_node_t;
34 typedef struct rhash_s rhash_t;
35 typedef rboolean (*r_hash_equalfunc)(rconstpointer key1, rconstpointer key2);
36 typedef unsigned int (*r_hash_hashfun)(rconstpointer key);
43 r_hash_equalfunc eqfunc;
48 #define R_HASH_INVALID_INDEXVAL ((unsigned long)-1)
50 #define r_hash_size(__h__) (((rsize_t)1) << (__h__)->nbits)
51 #define r_hash_mask(__h__) (r_hash_size(__h__) - 1)
52 rhash_t *r_hash_create(unsigned int nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc);
53 void r_hash_destroy(rhash_t* hash);
54 robject_t *r_hash_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy,
55 unsigned int nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc);
57 void r_hash_insert(rhash_t* hash, rconstpointer key, rpointer value);
58 void r_hash_remove(rhash_t* hash, rconstpointer key);
59 void r_hash_removeall(rhash_t* hash);
60 rpointer r_hash_lookup(rhash_t* hash, rconstpointer key);
61 void r_hash_insert_indexval(rhash_t* hash, rconstpointer key, unsigned long index);
62 unsigned long r_hash_lookup_indexval(rhash_t* hash, rconstpointer key);
63 unsigned long r_hash_taillookup_indexval(rhash_t* hash, rconstpointer key);
64 rhash_node_t *r_hash_nodelookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key);
65 rhash_node_t *r_hash_nodetaillookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key);
66 rpointer r_hash_value(rhash_node_t *node);
67 unsigned long r_hash_indexval(rhash_node_t *node);
69 unsigned int r_hash_strhash(rconstpointer key);
70 rboolean r_hash_strequal(rconstpointer key1, rconstpointer key2);
71 unsigned int r_hash_rstrhash(rconstpointer key);
72 rboolean r_hash_rstrequal(rconstpointer key1, rconstpointer key2);
76 * Virtual methods implementation
78 void r_hash_cleanup(robject_t *obj);
79 robject_t *r_hash_copy(const robject_t *obj);