From: Arran Cudbard-Bell Date: Sat, 13 Apr 2024 15:51:08 +0000 (-0600) Subject: Add strings for htrie types and FR_HTRIE_AUTO X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92e1f60138dc82a922b24ee7aedc2df0d7b8286a;p=thirdparty%2Ffreeradius-server.git Add strings for htrie types and FR_HTRIE_AUTO --- diff --git a/src/lib/util/htrie.c b/src/lib/util/htrie.c index 89462ad9c44..efca3c57928 100644 --- a/src/lib/util/htrie.c +++ b/src/lib/util/htrie.c @@ -22,10 +22,20 @@ */ RCSID("$Id$") +#include #include +#include #define FUNC(_prefix, _op) ._op = (fr_htrie_ ##_op ## _t) fr_##_prefix##_## _op +fr_table_num_sorted_t const fr_htrie_type_table[] = { + { L("auto"), FR_HTRIE_AUTO }, + { L("hash"), FR_HTRIE_HASH }, + { L("rb"), FR_HTRIE_RB }, + { L("trie"), FR_HTRIE_TRIE }, +}; +size_t fr_htrie_type_table_len = NUM_ELEMENTS(fr_htrie_type_table); + static fr_htrie_funcs_t const default_funcs[] = { [FR_HTRIE_HASH] = { .match = (fr_htrie_find_t) fr_hash_table_find, @@ -133,6 +143,14 @@ fr_htrie_t *fr_htrie_alloc(TALLOC_CTX *ctx, ht->funcs = default_funcs[type]; return ht; + case FR_HTRIE_INVALID: + fr_assert_msg(0, "FR_TYPE_INVALID passed as htype"); + return NULL; + + case FR_HTRIE_AUTO: + fr_assert_msg(0, "FR_HTRIE_AUTO must be resolved to a concrete htype value using fr_htrie_hint()"); + return NULL; + default: return NULL; } diff --git a/src/lib/util/htrie.h b/src/lib/util/htrie.h index 5e08b33be65..809bb4324c9 100644 --- a/src/lib/util/htrie.h +++ b/src/lib/util/htrie.h @@ -51,8 +51,16 @@ typedef enum { FR_HTRIE_HASH, //!< Data is stored in a hash. FR_HTRIE_RB, //!< Data is stored in a rb tree. FR_HTRIE_TRIE, //!< Data is stored in a prefix trie. + FR_HTRIE_AUTO, //!< Automatically choose the best type. + ///< Must be not be passed to fr_htrie_alloc(). + ///< If the user selects this, you must + ///< call fr_htrie_hint() to determine the + ///< best type. } fr_htrie_type_t; +extern fr_table_num_sorted_t const fr_htrie_type_table[]; +extern size_t fr_htrie_type_table_len; + /** Which functions are used for the different operations * */