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.

197 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. dict.h
  5. Abstract:
  6. Simple dictionary data structure based on a hash table. The hash
  7. table gives constant time performance if the number of elements in
  8. the table is close to the number of bins allocated for the table.
  9. The dictionary does not provide automatic synchronization.
  10. Author:
  11. Matthew D Hendel (math) 8-Feb-2001
  12. Revision History:
  13. --*/
  14. #pragma once
  15. //
  16. // Dictionary entry. Use this the same way the LIST_ENTRY
  17. // structure is used; i.e., by embedding it into the structure you
  18. // will be adding to the list. By doing this we avoid a per-element
  19. // memory allocation.
  20. //
  21. typedef LIST_ENTRY STOR_DICTIONARY_ENTRY, *PSTOR_DICTIONARY_ENTRY;
  22. //
  23. // User-supplied GetKey routine.
  24. //
  25. typedef PVOID
  26. (*STOR_DICTIONARY_GET_KEY_ROUTINE)(
  27. IN PSTOR_DICTIONARY_ENTRY Entry
  28. );
  29. //
  30. // User-supplied compare key routine.
  31. //
  32. typedef LONG
  33. (*STOR_DICTIONARY_COMPARE_KEY_ROUTINE)(
  34. IN PVOID Key1,
  35. IN PVOID Key2
  36. );
  37. //
  38. // User-supplied hash routine.
  39. //
  40. typedef ULONG
  41. (*STOR_DICTIONARY_HASH_KEY_ROUTINE)(
  42. IN PVOID Key
  43. );
  44. //
  45. // Dictionary sstructure.
  46. //
  47. typedef struct _STOR_DICTIONARY {
  48. ULONG EntryCount;
  49. ULONG MaxEntryCount;
  50. POOL_TYPE PoolType;
  51. PSTOR_DICTIONARY_ENTRY Entries;
  52. STOR_DICTIONARY_GET_KEY_ROUTINE GetKeyRoutine;
  53. STOR_DICTIONARY_COMPARE_KEY_ROUTINE CompareKeyRoutine;
  54. STOR_DICTIONARY_HASH_KEY_ROUTINE HashKeyRoutine;
  55. } STOR_DICTIONARY, *PSTOR_DICTIONARY;
  56. //
  57. // Enumerator structure used for enumerating the elements in the dictionary.
  58. //
  59. typedef
  60. BOOLEAN
  61. (*STOR_ENUMERATE_ROUTINE)(
  62. IN struct _STOR_DICTIONARY_ENUMERATOR* Enumerator,
  63. IN PLIST_ENTRY Entry
  64. );
  65. typedef struct _STOR_DICTIONARY_ENUMERATOR {
  66. PVOID Context;
  67. STOR_ENUMERATE_ROUTINE EnumerateEntry;
  68. } STOR_DICTIONARY_ENUMERATOR, *PSTOR_DICTIONARY_ENUMERATOR;
  69. //
  70. // Default compare-key routine when the keys are ULONGs.
  71. //
  72. LONG
  73. StorCompareUlongKey(
  74. IN PVOID Key1,
  75. IN PVOID Key2
  76. );
  77. //
  78. // Default hash-key routine when the keys are ULONGs.
  79. //
  80. ULONG
  81. StorHashUlongKey(
  82. IN PVOID Key
  83. );
  84. NTSTATUS
  85. StorCreateDictionary(
  86. IN PSTOR_DICTIONARY Dictionary,
  87. IN ULONG EntryCount,
  88. IN POOL_TYPE PoolType,
  89. IN STOR_DICTIONARY_GET_KEY_ROUTINE GetKeyRoutine,
  90. IN STOR_DICTIONARY_COMPARE_KEY_ROUTINE CompareKeyRoutine, OPTIONAL
  91. IN STOR_DICTIONARY_HASH_KEY_ROUTINE HashKeyRoutine OPTIONAL
  92. );
  93. NTSTATUS
  94. StorInsertDictionary(
  95. IN PSTOR_DICTIONARY Dictionary,
  96. IN PSTOR_DICTIONARY_ENTRY Entry
  97. );
  98. NTSTATUS
  99. StorRemoveDictionary(
  100. IN PSTOR_DICTIONARY Dictionary,
  101. IN PVOID Key,
  102. OUT PSTOR_DICTIONARY_ENTRY* Entry OPTIONAL
  103. );
  104. NTSTATUS
  105. StorFindDictionary(
  106. IN PSTOR_DICTIONARY Dictionary,
  107. IN PVOID Key,
  108. OUT PSTOR_DICTIONARY_ENTRY* Entry OPTIONAL
  109. );
  110. VOID
  111. StorEnumerateDictionary(
  112. IN PSTOR_DICTIONARY Dict,
  113. IN PSTOR_DICTIONARY_ENUMERATOR Enumerator
  114. );
  115. ULONG
  116. INLINE
  117. StorGetDictionaryCount(
  118. IN PSTOR_DICTIONARY Dictionary
  119. )
  120. {
  121. return Dictionary->EntryCount;
  122. }
  123. ULONG
  124. INLINE
  125. StorGetDictionaryMaxCount(
  126. IN PSTOR_DICTIONARY Dictionary
  127. )
  128. {
  129. return Dictionary->MaxEntryCount;
  130. }
  131. ULONG
  132. INLINE
  133. StorGetDictionaryFullness(
  134. IN PSTOR_DICTIONARY Dictionary
  135. )
  136. /*++
  137. Routine Description:
  138. Return the 'fullness' of the dictionary. As a general rule, when the
  139. dictionary reaches XXX % full, it should be expanded to
  140. Arguments:
  141. Dictionary -
  142. Return Value:
  143. This is returned as a percentage, e.g., 50 = 50% full, 100 = 100%
  144. full, 200 = 200% full, etc.
  145. --*/
  146. {
  147. return ((Dictionary->MaxEntryCount * 100) / Dictionary->EntryCount);
  148. }