Leaked source code of windows server 2003
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.

130 lines
4.3 KiB

  1. /*
  2. * tree.h
  3. *
  4. * data type providing a map from a key to a value, where the value is
  5. * an arbitrary area of storage.
  6. *
  7. * The current implementation of this is a binary search tree with no
  8. * balancing, so it will be inefficient if the data is presented in
  9. * strict ascending or descending order.
  10. *
  11. * all memory is allocated from a gmem_* heap that is passed on
  12. * creation of the tree.
  13. *
  14. * include gutils.h before this.
  15. */
  16. /* handle for a tree */
  17. typedef struct tree FAR * TREE;
  18. /* keys in these trees are DWORDs */
  19. typedef DWORD TREEKEY;
  20. /* some sort of place-holder understood only by tree_search and
  21. * tree_addafter
  22. */
  23. typedef struct treeitem FAR * TREEITEM;
  24. /* pointer to one of these place holders */
  25. typedef TREEITEM FAR * PTREEITEM;
  26. /*
  27. * create an empty tree and return a handle to it. Pass the heap to
  28. * be used for all memory allocations.
  29. */
  30. TREE APIENTRY tree_create(HANDLE hHeap);
  31. /* delete a tree and discard any associated memory. The tree need not be
  32. * empty. This will discard the elements of the tree; but if these
  33. * contained pointers to further data blocks, these will not be discarded-
  34. * you must free these before deleting the tree.
  35. */
  36. void APIENTRY tree_delete(TREE tree);
  37. /* add new element to the tree, mapping the key given to the value
  38. *
  39. * a block of data of length bytes will be inserted in the tree, mapped
  40. * to this key, a pointer to this block will be returned. if the
  41. * value pointer is non-null, the block value[0..length-1] will be copied
  42. * to the new block.
  43. *
  44. * if the key already exists, the value block will be replaced with the
  45. * new size and (if value is non-null) contents.
  46. */
  47. LPVOID APIENTRY tree_update(TREE tree, TREEKEY key, LPVOID value, UINT length);
  48. /* return a pointer to the value associated with a given key in this tree.
  49. * returns NULL if the key is not found.
  50. */
  51. LPVOID APIENTRY tree_find(TREE tree, TREEKEY key);
  52. /*
  53. * a common tree operation is to insert a new element into the
  54. * tree only if that key is not found, and otherwise to update in some
  55. * way the existing value. Using the standard functions above, that
  56. * would require one lookup for the tree_find, and then a second lookup
  57. * to insert the new element.
  58. *
  59. * the two functions below provide an optimisation over this. tree_search
  60. * will return the value if found; if not, it will return NULL, and set
  61. * pitem to a pointer to a place holder in the tree where the item
  62. * should be inserted. tree_addafter takes this placeholder as
  63. * an argument, and will insert the key/value in the tree at that point.
  64. *
  65. * as for tree_update, the value pointer can be NULL - in this case
  66. * the block is allocated on the tree, but not initialised.
  67. *
  68. * the return value from tree_addafter is a pointer to the value block in
  69. * the tree
  70. */
  71. LPVOID APIENTRY tree_search(TREE tree, TREEKEY key, PTREEITEM place);
  72. LPVOID APIENTRY tree_addafter(TREE tree, PTREEITEM place, TREEKEY key, LPVOID value,
  73. UINT length);
  74. /* -- ctree ---------------
  75. *
  76. * this is a type of tree based on the tree_ data type above, that implements
  77. * counting for insertions of identical keys.
  78. *
  79. * ctree_update, if the key is unique, will insert the object and set the count
  80. * to 1. if the key is not unique, it will just increment the reference count.
  81. *
  82. * ctree_getcount returns the reference count for a tree.
  83. * ctree_find returns the first value inserted for that key, if any
  84. */
  85. /*
  86. * create an empty counting-tree and return handle. pass in the gmem_init()
  87. * heap to be used for all memory allocations.
  88. */
  89. TREE APIENTRY ctree_create(HANDLE hHeap);
  90. /*
  91. * delete a tree and all memory associated directly with it.
  92. */
  93. void APIENTRY ctree_delete(TREE tree);
  94. /*
  95. * if the KEY is unique within the tree, insert the value and
  96. * set the count for that key to 1. If the key is not unique, add one to
  97. * the reference count for that key but leave the value untouched.
  98. */
  99. LPVOID APIENTRY ctree_update(TREE tree, TREEKEY key, LPVOID value, UINT length);
  100. /*
  101. * find the reference count for the given key
  102. */
  103. long APIENTRY ctree_getcount(TREE tree, TREEKEY key);
  104. /*
  105. * return the value for the given key (note this will be the value for
  106. * the first insertion of this key
  107. */
  108. LPVOID APIENTRY ctree_find(TREE tree, TREEKEY key);