You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

btrie.h 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Level-Compressed Tree Bitmap (LC-TBM) Trie implementation
  2. *
  3. * Contributed by Geoffrey T. Dairiki <dairiki@dairiki.org>
  4. *
  5. * This file is released under a "Three-clause BSD License".
  6. *
  7. * Copyright (c) 2013, Geoffrey T. Dairiki
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer in the documentation and/or other materials provided
  20. * with the distribution.
  21. *
  22. * * Neither the name of Geoffrey T. Dairiki nor the names of other
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEOFFREY
  30. * T. DAIRIKI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  33. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  34. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  36. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  37. * DAMAGE.
  38. */
  39. #ifndef _BTRIE_H_INCLUDED
  40. #define _BTRIE_H_INCLUDED
  41. #include "config.h"
  42. #include <stdint.h>
  43. typedef uint8_t btrie_oct_t;
  44. /* maximum length of bit string btrie_walk() can handle
  45. *
  46. * note: this limit is necessitated by the use of fixed length buffers
  47. * in btrie_walk() --- btrie_add_prefix() and btrie_lookup() impose no
  48. * limit on the length of bitstrings
  49. */
  50. #define BTRIE_MAX_PREFIX 128
  51. struct btrie;
  52. struct memory_pool_s;
  53. struct btrie *btrie_init(struct memory_pool_s *mp);
  54. enum btrie_result {
  55. BTRIE_OKAY = 0,
  56. BTRIE_ALLOC_FAILED = -1,
  57. BTRIE_DUPLICATE_PREFIX = 1
  58. };
  59. enum btrie_result btrie_add_prefix(struct btrie *btrie,
  60. const btrie_oct_t *prefix, unsigned len, const void *data);
  61. const void *btrie_lookup(const struct btrie *btrie, const btrie_oct_t *pfx,
  62. unsigned len);
  63. const char *btrie_stats(const struct btrie *btrie, unsigned int duplicates);
  64. #ifndef NO_MASTER_DUMP
  65. typedef void btrie_walk_cb_t(const btrie_oct_t *prefix, unsigned len,
  66. const void *data, int post, void *user_data);
  67. void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback,
  68. void *user_data);
  69. #endif /* not NO_MASTER_DUMP */
  70. #endif /* _BTRIE_H_INCLUDED */