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.

71 lines
3.0 KiB

  1. #pragma once
  2. typedef struct _HASH_NODE
  3. {
  4. // hash structural links
  5. struct _HASH_NODE *pUpLink; // up level link to the "parent" node
  6. LIST_ENTRY lstHoriz; // horizontal links to "brother" nodes
  7. LIST_ENTRY lstDown; // down level links to "child" nodes
  8. // hash node data
  9. LPWSTR wszKey; // partial key info
  10. LPVOID pObject; // pointer to data opaque object
  11. } HASH_NODE, *PHASH_NODE;
  12. typedef struct _HASH
  13. {
  14. BOOL bValid; // boolean telling whether the HASH is a valid object
  15. CRITICAL_SECTION csMutex;
  16. PHASH_NODE pRoot;
  17. } HASH, *PHASH;
  18. //--------- Private calls ------------------------------------------------
  19. // Matches the keys one against the other.
  20. UINT // [RET] number of matching chars
  21. HshPrvMatchKeys(
  22. LPWSTR wszKey1, // [IN] key 1
  23. LPWSTR wszKey2); // [IN] key 2
  24. // deletes all the pHash tree - doesn't touch the pObjects from within
  25. // (if any)
  26. VOID
  27. HshDestructor(
  28. PHASH_NODE pHash); // [IN] hash tree to delete
  29. //--------- Public calls -------------------------------------------------
  30. //
  31. // Initializes a HASH structure
  32. DWORD
  33. HshInitialize(PHASH pHash);
  34. // Cleans all resources referenced by a HASH structures
  35. VOID
  36. HshDestroy(PHASH pHash);
  37. // Inserts an opaque object into the cache. The object is keyed on a wstring
  38. // The call could alter the structure of the hash, hence it returns the reference
  39. // to the updated hash.
  40. DWORD // [RET] win32 error code
  41. HshInsertObjectRef(
  42. PHASH_NODE pHash, // [IN] hash to operate on
  43. LPWSTR wszKey, // [IN] key of the object to insert
  44. LPVOID pObject, // [IN] object itself to insert in the cache
  45. PHASH_NODE *ppOutHash); // [OUT] pointer to the updated hash
  46. // Retrieves an object from the hash. The hash structure is not touched in
  47. // any manner.
  48. DWORD // [RET] win32 error code
  49. HshQueryObjectRef(
  50. PHASH_NODE pHash, // [IN] hash to operate on
  51. LPWSTR wszKey, // [IN] key of the object to retrieve
  52. PHASH_NODE *ppHashNode); // [OUT] hash node referencing the queried object
  53. // Removes the object referenced by the pHash node. This could lead to one or
  54. // more hash node removals (if a leaf node on an isolated branch) but it could
  55. // also let the hash node untouched (i.e. internal node).
  56. // It is the caller's responsibility to clean up the object pointed by ppObject
  57. DWORD // [RET] win32 error code
  58. HshRemoveObjectRef(
  59. PHASH_NODE pHash, // [IN] hash to operate on
  60. PHASH_NODE pRemoveNode, // [IN] hash node to clear the reference to pObject
  61. LPVOID *ppObject, // [OUT] pointer to the object whose reference has been cleared
  62. PHASH_NODE *ppOutHash); // [OUT] pointer to the updated hash