CAvl_header.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @file CAvl_header.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. // Preprocessor inputs:
  30. // CAVL_PARAM_USE_COUNTS - whether to keep node counts (0 or 1)
  31. // CAVL_PARAM_NAME - name of this data structure
  32. // CAVL_PARAM_ENTRY - type of entry
  33. // CAVL_PARAM_LINK - type of node link (usually pointer)
  34. // CAVL_PARAM_KEY - type of key
  35. // CAVL_PARAM_ARG - type of argument pass through to comparisons
  36. // CAVL_PARAM_COUNT - type of count
  37. // CAVL_PARAM_COUNT_MAX - maximum value of count
  38. // CAVL_PARAM_NULL - invalid link
  39. // CAVL_PARAM_DEREF(arg, link) - dereference a non-null link
  40. // CAVL_PARAM_COMPARE_NODES(arg, node1, node2) - compare nodes
  41. // CAVL_PARAM_COMPARE_KEY_NODE(arg, key1, node2) - compare key and node
  42. // CAVL_PARAM_NODE_LINK - link member in node
  43. // CAVL_PARAM_NODE_BALANCE - balance member in node
  44. // CAVL_PARAM_NODE_PARENT - parent member in node
  45. // CAVL_PARAM_NODE_COUNT - count member in node (if CAVL_PARAM_USE_COUNTS)
  46. // types
  47. #define CAvl CAVL_PARAM_NAME
  48. #define CAvlEntry CAVL_PARAM_ENTRY
  49. #define CAvlLink CAVL_PARAM_LINK
  50. #define CAvlNode MERGE(CAvl, Node)
  51. #define CAvlArg CAVL_PARAM_ARG
  52. #define CAvlKey CAVL_PARAM_KEY
  53. #define CAvlCount CAVL_PARAM_COUNT
  54. // static values
  55. #define CAvlNullLink MERGE(CAvl, NullLink)
  56. // public functions
  57. #define CAvl_Init MERGE(CAvl, _Init)
  58. #define CAvl_Deref MERGE(CAvl, _Deref)
  59. #define CAvl_Insert MERGE(CAvl, _Insert)
  60. #define CAvl_Remove MERGE(CAvl, _Remove)
  61. #define CAvl_Lookup MERGE(CAvl, _Lookup)
  62. #define CAvl_LookupExact MERGE(CAvl, _LookupExact)
  63. #define CAvl_GetFirst MERGE(CAvl, _GetFirst)
  64. #define CAvl_GetLast MERGE(CAvl, _GetLast)
  65. #define CAvl_GetNext MERGE(CAvl, _GetNext)
  66. #define CAvl_GetPrev MERGE(CAvl, _GetPrev)
  67. #define CAvl_IsEmpty MERGE(CAvl, _IsEmpty)
  68. #define CAvl_Verify MERGE(CAvl, _Verify)
  69. #define CAvl_Count MERGE(CAvl, _Count)
  70. #define CAvl_IndexOf MERGE(CAvl, _IndexOf)
  71. #define CAvl_GetAt MERGE(CAvl, _GetAt)
  72. // private stuff
  73. #define CAvl_link(node) ((node).ptr->CAVL_PARAM_NODE_LINK)
  74. #define CAvl_balance(node) ((node).ptr->CAVL_PARAM_NODE_BALANCE)
  75. #define CAvl_parent(node) ((node).ptr->CAVL_PARAM_NODE_PARENT)
  76. #define CAvl_count(node) ((node).ptr->CAVL_PARAM_NODE_COUNT)
  77. #define CAvl_nullnode MERGE(CAvl, __nullnode)
  78. #define CAvl_compare_nodes MERGE(CAvl, __compare_nodes)
  79. #define CAvl_compare_key_node MERGE(CAvl, __compare_key_node)
  80. #define CAvl_check_parent MERGE(CAvl, __check_parent)
  81. #define CAvl_verify_recurser MERGE(CAvl, __verify_recurser)
  82. #define CAvl_assert_tree MERGE(CAvl, __assert_tree)
  83. #define CAvl_update_count_from_children MERGE(CAvl, __update_count_from_children)
  84. #define CAvl_rotate MERGE(CAvl, __rotate)
  85. #define CAvl_subtree_min MERGE(CAvl, __subtree_min)
  86. #define CAvl_subtree_max MERGE(CAvl, __subtree_max)
  87. #define CAvl_replace_subtree_fix_counts MERGE(CAvl, __replace_subtree_fix_counts)
  88. #define CAvl_swap_nodes MERGE(CAvl, __swap_nodes)
  89. #define CAvl_rebalance MERGE(CAvl, __rebalance)
  90. #define CAvl_MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
  91. #define CAvl_OPTNEG(_a, _neg) ((_neg) ? -(_a) : (_a))