knot_mm_t mm;
knot_compr_t compr;
};
-typedef struct {
- void *root;
- struct knot_mm *pool;
-} map_t;
typedef struct trie trie_t;
struct kr_qflags {
_Bool NO_MINIMIZE : 1;
knot_mm_t mm;
knot_compr_t compr;
};
-typedef struct {
- void *root;
- struct knot_mm *pool;
-} map_t;
typedef struct trie trie_t;
struct kr_qflags {
_Bool NO_MINIMIZE : 1;
knot_pktsection_t
knot_compr_t
struct knot_pkt
- # lib/generic/
- map_t
#trie_t inside is private to libknot
typedef trie_t
# libkres
}
}
-/** Endpoint visitor (see @file map.h) */
+/** Endpoint visitor (see @file trie.h) */
static int close_key(trie_val_t *val, void* net)
{
endpoint_array_t *ep_array = *val;
#include "daemon/tls.h"
#include "lib/generic/array.h"
-#include "lib/generic/map.h"
#include "lib/generic/trie.h"
#include <uv.h>
#include "daemon/worker.h"
#include "lib/dnssec/ta.h"
#include "lib/dnssec.h"
-#include "lib/generic/map.h"
#include "lib/generic/array.h"
#include "lib/generic/trie.h"
#include "lib/utils.h"
Copyright: 2011 Joey Adams
License: Expat
-Files: lib/generic/map.c lib/generic/map.h
-Copyright: Dan Bernstein
- Jonas Gehring
- Adam Langley
- Marek Vavrusa
-License: public-domain
-
Files: modules/policy/lua-aho-corasick/*
Copyright: 2013 CloudFlare, Inc.
License: BSD-3-CloudFlare
* array_ - a set of simple macros to make working with dynamic arrays easier.
* queue_ - a FIFO + LIFO queue.
-* map_ - a `Crit-bit tree`_ key-value map implementation (public domain) that comes with tests.
-* set_ - set abstraction implemented on top of ``map`` (unused now).
* pack_ - length-prefixed list of objects (i.e. array-list).
* lru_ - LRU-like hash table
* trie_ - a trie-based key-value map, taken from knot-dns
.. doxygenfile:: queue.h
:project: libkres
-map
-~~~
-
-.. doxygenfile:: map.h
- :project: libkres
-
-set
-~~~
-
-.. doxygenfile:: set.h
- :project: libkres
-
pack
~~~~
+++ /dev/null
-/*
- * critbit89 - A crit-bit tree implementation for strings in C89
- * Written by Jonas Gehring <jonas@jgehring.net>
- * Implemented key-value storing by Marek Vavrusa <marek.vavrusa@nic.cz>
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- * The code makes the assumption that malloc returns pointers aligned at at
- * least a two-byte boundary. Since the C standard requires that malloc return
- * pointers that can store any type, there are no commonly-used toolchains for
- * which this assumption is false.
- *
- * See https://github.com/agl/critbit/blob/master/critbit.pdf for reference.
- */
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "map.h"
-#include "lib/utils.h"
-
- /* Exports */
-#if defined _WIN32 || defined __CYGWIN__
- #define EXPORT __attribute__ ((dllexport))
-#else
- #define EXPORT __attribute__ ((visibility ("default")))
-#endif
-
-#ifdef _MSC_VER /* MSVC */
- typedef unsigned __int8 uint8_t;
- typedef unsigned __int32 uint32_t;
- #ifdef _WIN64
- typedef signed __int64 intptr_t;
- #else
- typedef _W64 signed int intptr_t;
- #endif
-#else /* Not MSVC */
- #include <stdint.h>
-#endif
-
-typedef struct {
- void* value;
- uint8_t key[];
-} cb_data_t;
-
-typedef struct {
- void *child[2];
- uint32_t byte;
- uint8_t otherbits;
-} cb_node_t;
-
-/* Return true if ptr is internal node. */
-static inline int ref_is_internal(const uint8_t *p)
-{
- return 1 & (intptr_t)p;
-}
-
-/* Get internal node. */
-static inline cb_node_t *ref_get_internal(uint8_t *p)
-{
- return (cb_node_t *)(p - 1);
-}
-
-/* Static helper functions */
-static void cbt_traverse_delete(map_t *map, void *top)
-{
- uint8_t *p = top;
- if (ref_is_internal(p)) {
- cb_node_t *q = ref_get_internal(p);
- cbt_traverse_delete(map, q->child[0]);
- cbt_traverse_delete(map, q->child[1]);
- mm_free(map->pool, q);
- } else {
- mm_free(map->pool, p);
- }
-}
-
-static int cbt_traverse_prefixed(void *top,
- int (*callback)(const char *, void *, void *), void *baton)
-{
- uint8_t *p = top;
- cb_data_t *x = (cb_data_t *)top;
-
- if (ref_is_internal(p)) {
- cb_node_t *q = ref_get_internal(p);
- int ret = 0;
-
- ret = cbt_traverse_prefixed(q->child[0], callback, baton);
- if (ret != 0) {
- return ret;
- }
- ret = cbt_traverse_prefixed(q->child[1], callback, baton);
- if (ret != 0) {
- return ret;
- }
- return 0;
- }
-
- return (callback)((const char *)x->key, x->value, baton);
-}
-
-static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void *value)
-{
- cb_data_t *x = mm_alloc(map->pool, sizeof(cb_data_t) + len);
- if (x != NULL) {
- x->value = value;
- memcpy(x->key, str, len);
- }
- return x;
-}
-
-/*! Like map_contains, but also set the value, if passed and found. */
-static int cbt_get(map_t *map, const char *str, void **value)
-{
- const uint8_t *ubytes = (void *)str;
- const size_t ulen = strlen(str);
- uint8_t *p = map->root;
- cb_data_t *x = NULL;
-
- if (p == NULL) {
- return 0;
- }
-
- while (ref_is_internal(p)) {
- cb_node_t *q = ref_get_internal(p);
- uint8_t c = 0;
- int direction;
-
- if (q->byte < ulen) {
- c = ubytes[q->byte];
- }
- direction = (1 + (q->otherbits | c)) >> 8;
-
- p = q->child[direction];
- }
-
- x = (cb_data_t *)p;
- if (strcmp(str, (const char *)x->key) == 0) {
- if (value != NULL) {
- *value = x->value;
- }
- return 1;
- }
-
- return 0;
-}
-
-/*! Returns non-zero if map contains str */
-EXPORT int map_contains(map_t *map, const char *str)
-{
- return cbt_get(map, str, NULL);
-}
-
-EXPORT void *map_get(map_t *map, const char *str)
-{
- void *v = NULL;
- cbt_get(map, str, &v);
- return v;
-}
-
-EXPORT int map_set(map_t *map, const char *str, void *val)
-{
- const uint8_t *const ubytes = (void *)str;
- const size_t ulen = strlen(str);
- uint8_t *p = map->root;
- uint8_t c = 0, *x = NULL;
- uint32_t newbyte = 0;
- uint32_t newotherbits = 0;
- int direction = 0, newdirection = 0;
- cb_node_t *newnode = NULL;
- cb_data_t *data = NULL;
- void **wherep = NULL;
-
- if (p == NULL) {
- map->root = cbt_make_data(map, (const uint8_t *)str, ulen + 1, val);
- if (map->root == NULL) {
- return ENOMEM;
- }
- return 0;
- }
-
- while (ref_is_internal(p)) {
- cb_node_t *q = ref_get_internal(p);
- c = 0;
- if (q->byte < ulen) {
- c = ubytes[q->byte];
- }
- direction = (1 + (q->otherbits | c)) >> 8;
-
- p = q->child[direction];
- }
-
- data = (cb_data_t *)p;
- for (newbyte = 0; newbyte < ulen; ++newbyte) {
- if (data->key[newbyte] != ubytes[newbyte]) {
- newotherbits = data->key[newbyte] ^ ubytes[newbyte];
- goto different_byte_found;
- }
- }
-
- if (data->key[newbyte] != 0) {
- newotherbits = data->key[newbyte];
- goto different_byte_found;
- }
- data->value = val;
- return 1;
-
-different_byte_found:
- newotherbits |= newotherbits >> 1;
- newotherbits |= newotherbits >> 2;
- newotherbits |= newotherbits >> 4;
- newotherbits = (newotherbits & ~(newotherbits >> 1)) ^ 255;
- c = data->key[newbyte];
- newdirection = (1 + (newotherbits | c)) >> 8;
-
- newnode = mm_alloc(map->pool, sizeof(cb_node_t));
- if (newnode == NULL) {
- return ENOMEM;
- }
-
- x = (uint8_t *)cbt_make_data(map, ubytes, ulen + 1, val);
- if (x == NULL) {
- mm_free(map->pool, newnode);
- return ENOMEM;
- }
-
- newnode->byte = newbyte;
- newnode->otherbits = newotherbits;
- newnode->child[1 - newdirection] = x;
-
- /* Insert into map */
- wherep = &map->root;
- for (;;) {
- cb_node_t *q;
- p = *wherep;
- if (!ref_is_internal(p)) {
- break;
- }
-
- q = ref_get_internal(p);
- if (q->byte > newbyte) {
- break;
- }
- if (q->byte == newbyte && q->otherbits > newotherbits) {
- break;
- }
-
- c = 0;
- if (q->byte < ulen) {
- c = ubytes[q->byte];
- }
- direction = (1 + (q->otherbits | c)) >> 8;
- wherep = q->child + direction;
- }
-
- newnode->child[newdirection] = *wherep;
- *wherep = (void *)(1 + (char *)newnode);
- return 0;
-}
-
-/*! Deletes str from the map, returns 0 on success */
-EXPORT int map_del(map_t *map, const char *str)
-{
- const uint8_t *ubytes = (void *)str;
- const size_t ulen = strlen(str);
- uint8_t *p = map->root;
- void **wherep = NULL, **whereq = NULL;
- cb_node_t *q = NULL;
- cb_data_t *data = NULL;
- int direction = 0;
-
- if (map->root == NULL) {
- return 1;
- }
- wherep = &map->root;
-
- while (ref_is_internal(p)) {
- uint8_t c = 0;
- whereq = wherep;
- q = ref_get_internal(p);
-
- if (q->byte < ulen) {
- c = ubytes[q->byte];
- }
- direction = (1 + (q->otherbits | c)) >> 8;
- wherep = q->child + direction;
- p = *wherep;
- }
-
- data = (cb_data_t *)p;
- if (strcmp(str, (const char *)data->key) != 0) {
- return 1;
- }
- mm_free(map->pool, p);
-
- if (!whereq) {
- map->root = NULL;
- return 0;
- }
-
- *whereq = q->child[1 - direction];
- mm_free(map->pool, q);
- return 0;
-}
-
-/*! Clears the given map */
-EXPORT void map_clear(map_t *map)
-{
- if (map->root) {
- cbt_traverse_delete(map, map->root);
- }
- map->root = NULL;
-}
-
-/*! Calls callback for all strings in map with the given prefix */
-EXPORT int map_walk_prefixed(map_t *map, const char *prefix,
- int (*callback)(const char *, void *, void *), void *baton)
-{
- if (!map) {
- return 0;
- }
-
- const uint8_t *ubytes = (void *)prefix;
- const size_t ulen = strlen(prefix);
- uint8_t *p = map->root;
- uint8_t *top = p;
- cb_data_t *data = NULL;
-
- if (p == NULL) {
- return 0;
- }
-
- while (ref_is_internal(p)) {
- cb_node_t *q = ref_get_internal(p);
- uint8_t c = 0;
- int direction;
-
- if (q->byte < ulen) {
- c = ubytes[q->byte];
- }
- direction = (1 + (q->otherbits | c)) >> 8;
-
- p = q->child[direction];
- if (q->byte < ulen) {
- top = p;
- }
- }
-
- data = (cb_data_t *)p;
- if (strlen((const char *)data->key) < ulen || memcmp(data->key, prefix, ulen) != 0) {
- return 0; /* No strings match */
- }
-
- return cbt_traverse_prefixed(top, callback, baton);
-}
+++ /dev/null
-/*
- * critbit89 - A crit-bit map implementation for strings in C89
- * Written by Jonas Gehring <jonas@jgehring.net>
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-/**
- * @file map.h
- * @brief A Crit-bit tree key-value map implementation.
- *
- * @warning If the user provides a custom allocator, it must return addresses aligned to 2B boundary.
- *
- * # Example usage:
- *
- * @code{.c}
- * map_t map = map_make(NULL);
- *
- * // Custom allocator (optional)
- * map.malloc = &mymalloc;
- * map.baton = &mymalloc_context;
- *
- * // Insert k-v pairs
- * int values = { 42, 53, 64 };
- * if (map_set(&map, "princess", &values[0]) != 0 ||
- * map_set(&map, "prince", &values[1]) != 0 ||
- * map_set(&map, "leia", &values[2]) != 0) {
- * fail();
- * }
- *
- * // Test membership
- * if (map_contains(&map, "leia")) {
- * success();
- * }
- *
- * // Prefix search
- * int i = 0;
- * int count(const char *k, void *v, void *ext) { (*(int *)ext)++; return 0; }
- * if (map_walk_prefixed(map, "princ", count, &i) == 0) {
- * printf("%d matches\n", i);
- * }
- *
- * // Delete
- * if (map_del(&map, "badkey") != 0) {
- * fail(); // No such key
- * }
- *
- * // Clear the map
- * map_clear(&map);
- * @endcode
- *
- * \addtogroup generics
- * @{
- */
-
-#pragma once
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct knot_mm; /* avoid the unnecessary include */
-
-/** Main data structure */
-typedef struct {
- void *root;
- struct knot_mm *pool;
-} map_t;
-
-/** Creates an new empty critbit map. Pass NULL for malloc+free. */
-static inline map_t map_make(struct knot_mm *pool)
-{
- return (map_t){ .root = NULL, .pool = pool };
-}
-
-/** Returns non-zero if map contains str */
-int map_contains(map_t *map, const char *str);
-
-/** Returns value if map contains str. Note: NULL may mean two different things. */
-void *map_get(map_t *map, const char *str);
-
-/** Inserts str into map. Returns 0 if new, 1 if replaced, or ENOMEM. */
-int map_set(map_t *map, const char *str, void *val);
-
-/** Deletes str from the map, returns 0 on success */
-int map_del(map_t *map, const char *str);
-
-/** Clears the given map */
-void map_clear(map_t *map);
-
-/**
- * Calls callback for all strings in map
- * See @fn map_walk_prefixed() for documentation on parameters.
- */
-#define map_walk(map, callback, baton) \
- map_walk_prefixed((map), "", (callback), (baton))
-
-/**
- * Calls callback for all strings in map with the given prefix.
- * Returns value immediately if a callback returns nonzero.
- *
- * @param map
- * @param prefix required string prefix (empty => all strings)
- * @param callback callback parameters are (key, value, baton)
- * @param baton passed uservalue
- */
-int map_walk_prefixed(map_t *map, const char *prefix,
- int (*callback)(const char *, void *, void *), void *baton);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
+++ /dev/null
-SPDXVersion: SPDX-2.1
-DataLicense: CC0-1.0
-SPDXID: SPDXRef-DOCUMENT
-DocumentName: map
-DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-d9b4db4c-062f-4add-89b6-f603224f5a2c
-
-PackageName: critbit89
-PackageDownloadLocation: git+https://github.com/jgehring/critbit89.git@4f7e1d2a5f4794e0d08cb408346973fb1e39489c#critbit.c
-PackageOriginator: Person: Jonas Gehring (jonas@jgehring.net)
-PackageLicenseDeclared: CC0-1.0
+++ /dev/null
-/* Copyright (C) 2015-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-/**
- * @file set.h
- * @brief A set abstraction implemented on top of map.
- *
- * @note The API is based on map.h, see it for more examples.
- *
- * # Example usage:
- *
- * @code{.c}
- * set_t set = set_make(NULL);
- *
- * // Insert keys
- * if (set_add(&set, "princess") != 0 ||
- * set_add(&set, "prince") != 0 ||
- * set_add(&set, "leia") != 0) {
- * fail();
- * }
- *
- * // Test membership
- * if (set_contains(&set, "leia")) {
- * success();
- * }
- *
- * // Prefix search
- * int i = 0;
- * int count(const char *s, void *n) { (*(int *)n)++; return 0; }
- * if (set_walk_prefixed(set, "princ", count, &i) == 0) {
- * printf("%d matches\n", i);
- * }
- *
- * // Delete
- * if (set_del(&set, "badkey") != 0) {
- * fail(); // No such key
- * }
- *
- * // Clear the set
- * set_clear(&set);
- * @endcode
- *
- * \addtogroup generics
- * @{
- */
-
-#pragma once
-
-#include <stddef.h>
-#include "map.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef map_t set_t;
-typedef int (set_walk_cb)(const char *, void *);
-
-/*! Creates an new, empty critbit set */
-#define set_make \
- map_make
-
-/*! Returns non-zero if set contains str */
-#define set_contains(set, str) \
- map_contains((set), (str))
-
-/*! Inserts str into set. Returns 0 if new, 1 if already present, or ENOMEM. */
-#define set_add(set, str) \
- map_set((set), (str), (void *)1)
-
-/*! Deletes str from the set, returns 0 on success */
-#define set_del(set, str) \
- map_del((set), (str))
-
-/*! Clears the given set */
-#define set_clear(set) \
- map_clear(set)
-
-/*! Calls callback for all strings in map */
-#define set_walk(set, callback, baton) \
- map_walk_prefixed((set), "", (callback), (baton))
-
-/*! Calls callback for all strings in set with the given prefix */
-#define set_walk_prefixed(set, prefix, callback, baton) \
- map_walk_prefixed((set), (prefix), (callback), (baton))
-
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
+++ /dev/null
-/* Copyright (C) 2014-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "tests/unit/test.h"
-#include "lib/generic/map.h"
-
-/*
- * Sample dictionary
- */
-static const char *dict[] = {
- "catagmatic", "prevaricator", "statoscope", "workhand", "benzamide",
- "alluvia", "fanciful", "bladish", "Tarsius", "unfast", "appropriative",
- "seraphically", "monkeypod", "deflectometer", "tanglesome", "zodiacal",
- "physiologically", "economizer", "forcepslike", "betrumpet",
- "Danization", "broadthroat", "randir", "usherette", "nephropyosis",
- "hematocyanin", "chrysohermidin", "uncave", "mirksome", "podophyllum",
- "siphonognathous", "indoor", "featheriness", "forwardation",
- "archruler", "soricoid", "Dailamite", "carmoisin", "controllability",
- "unpragmatical", "childless", "transumpt", "productive",
- "thyreotoxicosis", "oversorrow", "disshadow", "osse", "roar",
- "pantomnesia", "talcer", "hydrorrhoea", "Satyridae", "undetesting",
- "smoothbored", "widower", "sivathere", "pendle", "saltation",
- "autopelagic", "campfight", "unexplained", "Macrorhamphosus",
- "absconsa", "counterflory", "interdependent", "triact", "reconcentration",
- "oversharpness", "sarcoenchondroma", "superstimulate", "assessory",
- "pseudepiscopacy", "telescopically", "ventriloque", "politicaster",
- "Caesalpiniaceae", "inopportunity", "Helion", "uncompatible",
- "cephaloclasia", "oversearch", "Mahayanistic", "quarterspace",
- "bacillogenic", "hamartite", "polytheistical", "unescapableness",
- "Pterophorus", "cradlemaking", "Hippoboscidae", "overindustrialize",
- "perishless", "cupidity", "semilichen", "gadge", "detrimental",
- "misencourage", "toparchia", "lurchingly", "apocatastasis"
-};
-
-/* Insertions */
-static void test_insert(void **state)
-{
- map_t *tree = *state;
- int dict_size = sizeof(dict) / sizeof(const char *);
- int i;
-
- for (i = 0; i < dict_size; i++) {
- assert_int_equal(map_set(tree, dict[i], (void *)dict[i]), 0);
- }
-}
-
-/* Searching */
-static void test_get(void **state)
-{
- map_t *tree = *state;
- char *in;
- const char *notin = "not in tree";
-
- in = malloc(strlen(dict[23])+1);
- strcpy(in, dict[23]);
-
- assert_true(map_get(tree, in) == dict[23]);
- assert_true(map_get(tree, notin) == NULL);
- assert_true(map_get(tree, "") == NULL);
- in[strlen(in)/2] = '\0';
- assert_true(map_get(tree, in) == NULL);
-
- free(in);
-}
-
-/* Deletion */
-static void test_delete(void **state)
-{
- map_t *tree = *state;
- assert_int_equal(map_del(tree, dict[91]), 0);
- assert_false(map_contains(tree, dict[91]));
- assert_int_equal(map_del(tree, "most likely not in tree"), 1);
-}
-
-/* Test null value existence */
-static void test_null_value(void **state)
-{
- map_t *tree = *state;
- char *key = "foo";
-
- assert_int_equal(map_set(tree, key, (void *)0), 0);
- assert_true(map_contains(tree, key));
- assert_int_equal(map_del(tree, key), 0);
-}
-
-static void test_init(void **state)
-{
- static map_t tree;
- tree = map_make(NULL);
- *state = &tree;
- assert_non_null(*state);
-}
-
-static void test_deinit(void **state)
-{
- map_t *tree = *state;
- map_clear(tree);
-}
-
-/* Program entry point */
-int main(int argc, char **argv)
-{
- const UnitTest tests[] = {
- group_test_setup(test_init),
- unit_test(test_insert),
- unit_test(test_get),
- unit_test(test_delete),
- unit_test(test_null_value),
- group_test_teardown(test_deinit)
- };
-
- return run_group_tests(tests);
-}
+++ /dev/null
-/*
- * critbit89 - A crit-bit tree implementation for strings in C89
- * Written by Jonas Gehring <jonas@jgehring.net>
- * SPDX-License-Identifier: GPL-3.0-or-later
- */
-
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "tests/unit/test.h"
-#include "lib/generic/set.h"
-#include "lib/utils.h"
-
-
-/*
- * Sample dictionary: 100 random words from /usr/share/dict/words
- * Generated using random.org:
- * MAX=`wc -l < /usr/share/dict/words | tr -d " "`
- * for i in `curl "http://www.random.org/integers/?num=100&min=1&max=$MAX&col=1&base=10&format=plain&rnd=new"`; do
- * nl /usr/share/dict/words | grep -w $i | tr -d "0-9\t "
- * done
- */
-static const char *dict[] = {
- "catagmatic", "prevaricator", "statoscope", "workhand", "benzamide",
- "alluvia", "fanciful", "bladish", "Tarsius", "unfast", "appropriative",
- "seraphically", "monkeypod", "deflectometer", "tanglesome", "zodiacal",
- "physiologically", "economizer", "forcepslike", "betrumpet",
- "Danization", "broadthroat", "randir", "usherette", "nephropyosis",
- "hematocyanin", "chrysohermidin", "uncave", "mirksome", "podophyllum",
- "siphonognathous", "indoor", "featheriness", "forwardation",
- "archruler", "soricoid", "Dailamite", "carmoisin", "controllability",
- "unpragmatical", "childless", "transumpt", "productive",
- "thyreotoxicosis", "oversorrow", "disshadow", "osse", "roar",
- "pantomnesia", "talcer", "hydrorrhoea", "Satyridae", "undetesting",
- "smoothbored", "widower", "sivathere", "pendle", "saltation",
- "autopelagic", "campfight", "unexplained", "Macrorhamphosus",
- "absconsa", "counterflory", "interdependent", "triact", "reconcentration",
- "oversharpness", "sarcoenchondroma", "superstimulate", "assessory",
- "pseudepiscopacy", "telescopically", "ventriloque", "politicaster",
- "Caesalpiniaceae", "inopportunity", "Helion", "uncompatible",
- "cephaloclasia", "oversearch", "Mahayanistic", "quarterspace",
- "bacillogenic", "hamartite", "polytheistical", "unescapableness",
- "Pterophorus", "cradlemaking", "Hippoboscidae", "overindustrialize",
- "perishless", "cupidity", "semilichen", "gadge", "detrimental",
- "misencourage", "toparchia", "lurchingly", "apocatastasis"
-};
-
-/* Insertions */
-static void test_insert(void **state)
-{
- set_t *set = *state;
- int dict_size = sizeof(dict) / sizeof(const char *);
- int i;
-
- for (i = 0; i < dict_size; i++) {
- assert_int_equal(set_add(set, dict[i]), 0);
- }
-}
-
-/* Insertion of duplicate element */
-static void test_insert_dup(void **state)
-{
- set_t *set = *state;
- int dict_size = sizeof(dict) / sizeof(const char *);
- int i;
-
- for (i = 0; i < dict_size; i++) {
- if (!set_contains(set, dict[i])) {
- continue;
- }
- assert_int_equal(set_add(set, dict[i]), 1);
- }
-}
-
-/* Searching */
-static void test_contains(void **state)
-{
- set_t *set = *state;
- char *in;
- const char *notin = "not in set";
-
- in = malloc(strlen(dict[23])+1);
- strcpy(in, dict[23]);
-
- assert_true(set_contains(set, in));
- assert_false(set_contains(set, notin));
- assert_false(set_contains(set, ""));
- in[strlen(in)/2] = '\0';
- assert_false(set_contains(set, in));
-
- free(in);
-}
-
-/* Count number of items */
-static int count_cb(const char *s, void *_, void *n) { (*(int *)n)++; return 0; }
-static void test_complete(set_t *set, int n)
-{
- int i = 0;
- if (set_walk(set, count_cb, &i) != 0) {
- abort();
- }
- if (i != n) {
- abort();
- }
-}
-static void test_complete_full(void **state) { test_complete(*state, sizeof(dict) / sizeof(const char *)); }
-static void test_complete_zero(void **state) { test_complete(*state, 0); }
-
-/* Deletion */
-static void test_delete(void **state)
-{
- set_t *set = *state;
- assert_int_equal(set_del(set, dict[91]), 0);
- assert_int_equal(set_del(set, "most likely not in set"), 1);
-}
-
-/* Complete deletion */
-static void test_delete_all(void **state)
-{
- set_t *set = *state;
- int dict_size = sizeof(dict) / sizeof(const char *);
- int i;
-
- for (i = 0; i < dict_size; i++) {
- if (!set_contains(set, dict[i])) {
- continue;
- }
- assert_int_equal(set_del(set, dict[i]), 0);
- }
-}
-
-/* Fake allocator */
-static void *fake_malloc(void *b, size_t s) { return NULL; }
-static void test_allocator(void **state)
-{
- knot_mm_t fake_pool = { .ctx = NULL, .alloc = fake_malloc, .free = NULL };
- set_t set = set_make(&fake_pool);
- assert_int_equal(set_add(&set, dict[0]), ENOMEM);
-}
-
-/* Empty set */
-static void test_empty(void **state)
-{
- set_t *set = *state;
- assert_int_equal(set_contains(set, dict[1]), 0);
- assert_int_not_equal(set_del(set, dict[1]), 0);
-}
-
-/* Prefix walking */
-static void test_prefixes(void **state)
-{
- set_t *set = *state;
- int i = 0;
- if ((set_add(set, "1str") != 0) ||
- (set_add(set, "11str2") != 0) ||
- (set_add(set, "12str") != 0) ||
- (set_add(set, "11str") != 0)) {
- assert_int_equal(1, 0);
- }
-
- assert_int_equal(set_walk_prefixed(set, "11", count_cb, &i), 0);
- assert_int_equal(i, 2);
- i = 0;
- assert_int_equal(set_walk_prefixed(set, "13", count_cb, &i), 0);
- assert_int_equal(i, 0);
- i = 0;
- assert_int_equal(set_walk_prefixed(set, "12345678", count_cb, &i), 0);
- assert_int_equal(i, 0);
- i = 0;
- assert_int_equal(set_walk_prefixed(set, "11str", count_cb, &i), 0);
- assert_int_equal(i, 2);
-}
-
-static void test_clear(void **state)
-{
- set_t *set = *state;
- set_clear(set);
-}
-
-static void test_init(void **state)
-{
- static set_t set;
- set = set_make(NULL);
- *state = &set;
- assert_non_null(*state);
-}
-
-static void test_deinit(void **state)
-{
- set_t *set = *state;
- set_clear(set);
-}
-
-/* Program entry point */
-int main(int argc, char **argv)
-{
- const UnitTest tests[] = {
- group_test_setup(test_init),
- unit_test(test_insert),
- unit_test(test_complete_full),
- unit_test(test_insert_dup),
- unit_test(test_contains),
- unit_test(test_delete),
- unit_test(test_clear),
- unit_test(test_insert),
- unit_test(test_complete_full),
- unit_test(test_delete_all),
- unit_test(test_complete_zero),
- unit_test(test_allocator),
- unit_test(test_clear),
- unit_test(test_empty),
- unit_test(test_insert),
- unit_test(test_prefixes),
- group_test_teardown(test_deinit)
- };
-
- return run_group_tests(tests);
-}
'dnssec/signature.c',
'dnssec/ta.c',
'generic/lru.c',
- 'generic/map.c',
'generic/queue.c',
'generic/trie.c',
'layer/cache.c',
'dnssec/ta.h',
'generic/array.h',
'generic/lru.h',
- 'generic/map.h',
'generic/pack.h',
'generic/queue.h',
'generic/trie.h',
unit_tests += [
['array', files('generic/test_array.c')],
['lru', files('generic/test_lru.c')],
- ['map', files('generic/test_map.c')],
['pack', files('generic/test_pack.c')],
['queue', files('generic/test_queue.c')],
- ['set', files('generic/test_set.c')],
['trie', files('generic/test_trie.c')],
['module', files('test_module.c')],
['rplan', files('test_rplan.c')],
#include "lib/cookies/control.h"
#include "lib/cookies/lru_cache.h"
#include "lib/layer.h"
-#include "lib/generic/map.h"
#include "lib/generic/array.h"
#include "lib/selection.h"
#include "lib/rplan.h"