aboutsummaryrefslogtreecommitdiff
path: root/src/common/ht.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/ht.h')
-rw-r--r--src/common/ht.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common/ht.h b/src/common/ht.h
index 72fe5e2cb0..095bca356b 100644
--- a/src/common/ht.h
+++ b/src/common/ht.h
@@ -382,6 +382,31 @@ ht_string_hash(const char *s)
return 0; \
}
+/** Implements an over-optimized "find and insert if absent" block;
+ * not meant for direct usage by typical code, or usage outside the critical
+ * path.*/
+#define _HT_FIND_OR_INSERT(name, field, hashfn, head, eltype, elm, var, y, n) \
+ { \
+ struct name *_##var##_head = head; \
+ eltype **var; \
+ if (!_##var##_head->hth_table || \
+ _##var##_head->hth_n_entries >= _##var##_head->hth_load_limit) \
+ name##_HT_GROW(_##var##_head, _##var##_head->hth_n_entries+1); \
+ _HT_SET_HASH((elm), field, hashfn); \
+ var = _##name##_HT_FIND_P(_##var##_head, (elm)); \
+ if (*var) { \
+ y; \
+ } else { \
+ n; \
+ } \
+ }
+#define _HT_FOI_INSERT(field, head, elm, newent, var) \
+ { \
+ newent->field.hte_hash = (elm)->field.hte_hash; \
+ *var = newent; \
+ ++((head)->hth_n_entries); \
+ }
+
/*
* Copyright 2005, Nick Mathewson. Implementation logic is adapted from code
* by Cristopher Clark, retrofit to allow drop-in memory management, and to