Grab the lock before reading uid/gid related structure, this will
[ipfw.git] / dummynet / hashtable.h
diff --git a/dummynet/hashtable.h b/dummynet/hashtable.h
new file mode 100644 (file)
index 0000000..a20b7b4
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef __HASHTABLE_H_
+#define __HASHTABLE_H_
+
+/*
+ * new_table_init creates a table with the specified
+ *     number of buckets (size).
+ * obj_size is the size of individual objects (key+value),
+ * the first function is the hash function (called with the
+ *     size and the payload pointer)
+ * the second function is the compare function, to tell if two
+ *     objects are the same (XXX we could spare this if we also
+ *     pass a key_size and use a bcmp for comparisons)
+ * Not extensible at the moment.
+ * max_el and max_ratio currently unused.
+ */
+struct malloc_type;
+struct new_hash_table * new_table_init (int size, int obj_size,
+    uint32_t (hash_fn)(const void *, uint32_t size),
+    int (cmp_fn)(const void*, const void*),
+    struct malloc_type *mtype);
+
+/* add a new object to the table, return success/failure */
+int new_table_insert_obj (struct new_hash_table *h, const void *obj);
+
+/*
+ * returns a pointer to the matching object or NULL if not found.
+ * No refcounts.
+ */
+const void *new_table_extract_obj(struct new_hash_table *h, const void *key);
+
+/* remove an object from the table */
+int new_table_delete_obj(struct new_hash_table *h, const void *key);
+void *new_table_destroy(struct new_hash_table *h);
+
+/* return the number of elements in the table */
+int new_table_get_element(const struct new_hash_table *h);
+
+/* returns the first or next element. Works by hashing the
+ * current object and then finds the next one.
+ * If obj == NULL returns the first object in the table
+ */
+const void *table_next(struct new_hash_table *h, const void *obj);
+
+#endif