您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. {
  56. BTRIE_OKAY = 0,
  57. BTRIE_ALLOC_FAILED = -1,
  58. BTRIE_DUPLICATE_PREFIX = 1
  59. };
  60. enum btrie_result btrie_add_prefix(struct btrie *btrie,
  61. const btrie_oct_t *prefix, unsigned len, const void *data);
  62. const void *btrie_lookup(const struct btrie *btrie, const btrie_oct_t *pfx,
  63. unsigned len);
  64. const char *btrie_stats(const struct btrie *btrie, guint duplicates);
  65. #ifndef NO_MASTER_DUMP
  66. typedef void btrie_walk_cb_t(const btrie_oct_t *prefix, unsigned len,
  67. const void *data, int post, void *user_data);
  68. void btrie_walk(const struct btrie *btrie, btrie_walk_cb_t *callback,
  69. void *user_data);
  70. #endif /* not NO_MASTER_DUMP */
  71. #endif /* _BTRIE_H_INCLUDED */