Source code of Windows XP (NT5)
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.

94 lines
2.3 KiB

  1. /*
  2. File HashTab.h
  3. Definitions for creating/dealing with hash tables.
  4. Paul Mayfield, 3/30/98
  5. */
  6. #ifndef __HashTab_h
  7. #define __HashTab_h
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <winerror.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. // Defines signiture of hash function. Must return an index
  16. // between zero and the size passed into HashTabCreate.
  17. typedef ULONG (* HashTabHashFuncPtr)(HANDLE hData);
  18. // Defines a function type that compares a key to an element. This is
  19. // used for searches. Return same as strcmp.
  20. typedef int (* HashTabKeyCompFuncPtr)(HANDLE hKey, HANDLE hData);
  21. // Function prototype for allocation. If this is provided in a call to
  22. // HashTabCreate the hash table code will allocate using this function.
  23. // Semantics of function are similar to malloc -- return NULL on failure.
  24. typedef PVOID (* HashTabAllocFuncPtr)(ULONG ulSize);
  25. // Function prototype for cleanup. Similar to free.
  26. typedef VOID (* HashTabFreeFuncPtr)(PVOID pvData);
  27. // Function prototype for cleaning up elements. If provided in a call
  28. // to HashTabCreate, then it will be called once for each element when
  29. // HashTabCleanup is called.
  30. typedef VOID (* HashTabFreeElemFuncPtr)(HANDLE hData);
  31. //
  32. // Create a hash table
  33. //
  34. ULONG HashTabCreate (
  35. IN ULONG ulSize,
  36. IN HashTabHashFuncPtr pHash,
  37. IN HashTabKeyCompFuncPtr pCompKeyAndElem,
  38. IN OPTIONAL HashTabAllocFuncPtr pAlloc,
  39. IN OPTIONAL HashTabFreeFuncPtr pFree,
  40. IN OPTIONAL HashTabFreeElemFuncPtr pFreeElem,
  41. OUT HANDLE * phHashTab );
  42. //
  43. // Clean up the hash table.
  44. //
  45. ULONG HashTabCleanup (
  46. IN HANDLE hHashTab );
  47. //
  48. // Insert data in a hash table under the given key
  49. //
  50. ULONG HashTabInsert (
  51. IN HANDLE hHashTab,
  52. IN HANDLE hKey,
  53. IN HANDLE hData );
  54. //
  55. // Removes the data associated with the given key
  56. //
  57. ULONG HashTabRemove (
  58. IN HANDLE hHashTab,
  59. IN HANDLE hKey);
  60. //
  61. // Search in the tree for the data associated with the given key
  62. //
  63. ULONG HashTabFind (
  64. IN HANDLE hHashTab,
  65. IN HANDLE hKey,
  66. OUT HANDLE * phData );
  67. //
  68. // Find out how many elements are stored in the hash table
  69. //
  70. ULONG HashTabGetCount(
  71. IN HANDLE hHashTab,
  72. OUT ULONG* lpdwCount );
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif