]>
git.proxmox.com Git - mirror_frr.git/blob - lib/hash.h
2 * Copyright (C) 1998 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2, or (at your
9 * option) any later version.
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "frratomic.h"
28 DECLARE_MTYPE(HASH_BACKET
)
30 /* Default hash table size. */
31 #define HASH_INITIAL_SIZE 256 /* initial number of backets. */
32 #define HASH_THRESHOLD 10 /* expand when backet. */
34 #define HASHWALK_CONTINUE 0
35 #define HASHWALK_ABORT -1
39 /* if this backet is the head of the linked listed, len denotes the number of
40 * elements in the list */
44 struct hash_backet
*next
;
55 /* number of empty hash buckets */
57 /* sum of squares of bucket length */
64 struct hash_backet
**index
;
66 /* Hash table size. Must be power of 2 */
69 /* If expansion failed. */
72 /* Key make function. */
73 unsigned int (*hash_key
) (void *);
75 /* Data compare function. */
76 int (*hash_cmp
) (const void *, const void *);
81 struct hashstats stats
;
87 #define hashcount(X) ((X)->count)
89 extern struct hash
*hash_create (unsigned int (*) (void *),
90 int (*) (const void *, const void *),
92 extern struct hash
*hash_create_size (unsigned int, unsigned int (*) (void *),
93 int (*) (const void *, const void *),
96 extern void *hash_get (struct hash
*, void *, void * (*) (void *));
97 extern void *hash_alloc_intern (void *);
98 extern void *hash_lookup (struct hash
*, void *);
99 extern void *hash_release (struct hash
*, void *);
101 extern void hash_iterate (struct hash
*,
102 void (*) (struct hash_backet
*, void *), void *);
104 extern void hash_walk (struct hash
*,
105 int (*) (struct hash_backet
*, void *), void *);
107 extern void hash_clean (struct hash
*, void (*) (void *));
108 extern void hash_free (struct hash
*);
110 extern unsigned int string_hash_make (const char *);
112 extern void hash_cmd_init (void);
114 #endif /* _ZEBRA_HASH_H */