summaryrefslogtreecommitdiff
path: root/lib/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hash.h')
-rw-r--r--lib/hash.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/hash.h b/lib/hash.h
index bafb35a2a3..9395440acb 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -22,6 +22,7 @@
#define _ZEBRA_HASH_H
#include "memory.h"
+#include "frratomic.h"
DECLARE_MTYPE(HASH)
DECLARE_MTYPE(HASH_BACKET)
@@ -35,6 +36,10 @@ DECLARE_MTYPE(HASH_BACKET)
struct hash_backet
{
+ /* if this backet is the head of the linked listed, len denotes the number of
+ * elements in the list */
+ int len;
+
/* Linked list. */
struct hash_backet *next;
@@ -45,6 +50,14 @@ struct hash_backet
void *data;
};
+struct hashstats
+{
+ /* number of empty hash buckets */
+ _Atomic int empty;
+ /* sum of squares of bucket length */
+ _Atomic uint64_t ssq;
+};
+
struct hash
{
/* Hash backet. */
@@ -64,12 +77,19 @@ struct hash
/* Backet alloc. */
unsigned long count;
+
+ struct hashstats stats;
+
+ /* hash name */
+ char *name;
};
extern struct hash *hash_create (unsigned int (*) (void *),
- int (*) (const void *, const void *));
+ int (*) (const void *, const void *),
+ const char *);
extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *),
- int (*) (const void *, const void *));
+ int (*) (const void *, const void *),
+ const char *);
extern void *hash_get (struct hash *, void *, void * (*) (void *));
extern void *hash_alloc_intern (void *);
@@ -87,4 +107,6 @@ extern void hash_free (struct hash *);
extern unsigned int string_hash_make (const char *);
+extern void hash_cmd_init (void);
+
#endif /* _ZEBRA_HASH_H */