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.

145 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. spaset.hxx
  5. Abstract:
  6. This class implements a sparse number set with huge (<= ULONG) number
  7. of elements. The numset.cxx implementation uses too much memory when
  8. the number of elements is in the 100,000 range. The numbers stored are
  9. not in any particular order and this implementation only supports a
  10. subset of set operations.
  11. Author:
  12. Daniel Chan (danielch) 01-29-97
  13. --*/
  14. #if !defined(SPARSE_SET_DEFN)
  15. #define SPARSE_SET_DEFN
  16. #include "bigint.hxx"
  17. #if defined ( _AUTOCHECK_ )
  18. #define IFSUTIL_EXPORT
  19. #elif defined ( _IFSUTIL_MEMBER_ )
  20. #define IFSUTIL_EXPORT __declspec(dllexport)
  21. #else
  22. #define IFSUTIL_EXPORT __declspec(dllimport)
  23. #endif
  24. CONST USHORT SPA_SET_HASH_TABLE_SIZE = 256;
  25. CONST ULONG SPA_SET_HASH_ELEMENT_INC = 50;
  26. DECLARE_CLASS( SPARSE_SET );
  27. typedef struct _HASH_ELEMENT {
  28. BIG_INT elementCount; // number of elements in elements
  29. BIG_INT maxElementCount; // max. number of elements in element
  30. PBIG_INT elements; // pointer to an array of BIG_INTs
  31. };
  32. DEFINE_TYPE( _HASH_ELEMENT, HASH_ELEMENT );
  33. class SPARSE_SET : public OBJECT {
  34. public:
  35. IFSUTIL_EXPORT
  36. DECLARE_CONSTRUCTOR( SPARSE_SET );
  37. VIRTUAL
  38. IFSUTIL_EXPORT
  39. ~SPARSE_SET(
  40. );
  41. NONVIRTUAL
  42. IFSUTIL_EXPORT
  43. BOOLEAN
  44. Initialize(
  45. );
  46. NONVIRTUAL
  47. IFSUTIL_EXPORT
  48. BOOLEAN
  49. CheckAndAdd(
  50. IN BIG_INT Number,
  51. OUT PBOOLEAN Duplicate DEFAULT NULL
  52. );
  53. NONVIRTUAL
  54. IFSUTIL_EXPORT
  55. BOOLEAN
  56. RemoveAll(
  57. );
  58. NONVIRTUAL
  59. IFSUTIL_EXPORT
  60. BOOLEAN
  61. CheckAndRemove(
  62. IN BIG_INT Number,
  63. OUT PBOOLEAN DoesExists DEFAULT NULL
  64. );
  65. NONVIRTUAL
  66. BIG_INT
  67. QueryCardinality(
  68. ) CONST;
  69. NONVIRTUAL
  70. IFSUTIL_EXPORT
  71. VOID
  72. DumpHashTable(
  73. );
  74. private:
  75. NONVIRTUAL
  76. VOID
  77. Construct (
  78. );
  79. NONVIRTUAL
  80. VOID
  81. Destroy(
  82. );
  83. PHASH_ELEMENT _hashTable;
  84. BIG_INT _card;
  85. };
  86. INLINE
  87. BIG_INT
  88. SPARSE_SET::QueryCardinality(
  89. ) CONST
  90. /*++
  91. Routine Description:
  92. This routine computes the number of elements in the set.
  93. Arguments:
  94. None.
  95. Return Value:
  96. The number of elements in the set.
  97. --*/
  98. {
  99. return _card;
  100. }
  101. #endif // SPARSE_SET_DEFN