]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add strings for htrie types and FR_HTRIE_AUTO
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 13 Apr 2024 15:51:08 +0000 (09:51 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 13 Apr 2024 15:51:08 +0000 (09:51 -0600)
src/lib/util/htrie.c
src/lib/util/htrie.h

index 89462ad9c448990b67fe2e3ea2d21aca1b672326..efca3c5792829c563310161ae4feb280a12d3741 100644 (file)
  */
 RCSID("$Id$")
 
+#include <freeradius-devel/util/debug.h>
 #include <freeradius-devel/util/htrie.h>
+#include <freeradius-devel/util/table.h>
 
 #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;
        }
index 5e08b33be657216aec49cb8d9a06e0473f6612f3..809bb4324c97b5e3b82d912cd455a493a155a1ab 100644 (file)
@@ -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
  *
  */