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.

116 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. GenTable.hxx
  5. Abstract:
  6. Generic wrapper for a bucket hash class.
  7. Used for ID, ID[2], ID[3] and string index tables.
  8. Author:
  9. Mario Goertzel [MarioGo]
  10. Revision History:
  11. MarioGo 12-13-95 Pulled from uuid index hash table
  12. MarioGo 12-18-95 Changed to use generic keys.
  13. --*/
  14. #ifndef __GENERIC_TABLE_HXX
  15. #define __GENERIC_TABLE_HXX
  16. class CTableKey {
  17. public:
  18. virtual DWORD Hash() = 0;
  19. virtual BOOL Compare(CTableKey &tk) = 0;
  20. };
  21. class CHashTable;
  22. class CTableElement : public CReferencedObject
  23. {
  24. friend class CHashTable;
  25. public:
  26. CTableElement() : _pnext(0) {}
  27. ~CTableElement() { ASSERT(_pnext == 0); }
  28. virtual DWORD Hash() = 0;
  29. virtual BOOL Compare(CTableKey &tk) = 0;
  30. virtual BOOL Compare(CONST CTableElement *element) = 0;
  31. protected:
  32. void
  33. Unlink() {
  34. _pnext = 0;
  35. }
  36. CTableElement *
  37. Next() {
  38. return(_pnext);
  39. }
  40. CTableElement *
  41. Insert(IN CTableElement *pElement) {
  42. // Can be called on a null this pointer.
  43. pElement->_pnext = this;
  44. return(pElement);
  45. }
  46. CTableElement *
  47. RemoveMatching(CTableKey &tkRemove,
  48. CTableElement **ppRemoved);
  49. CTableElement *
  50. RemoveMatching(CTableElement *pRemove,
  51. CTableElement **ppRemoved
  52. );
  53. private:
  54. CTableElement *_pnext;
  55. };
  56. typedef CTableElement *pCTableElement;
  57. class CHashTable
  58. {
  59. public:
  60. CHashTable(ORSTATUS &status, UINT start_size = 32 );
  61. ~CHashTable();
  62. void Add(pCTableElement element);
  63. CTableElement *Lookup(CTableKey &tk);
  64. CTableElement *Remove(CTableKey &tk);
  65. void Remove(CTableElement *pElement);
  66. CTableElement *Another();
  67. DWORD Size() { return(_cElements); }
  68. private:
  69. CTableElement *
  70. RemoveHelper(DWORD hash);
  71. DWORD _cBuckets;
  72. DWORD _cElements;
  73. CTableElement **_buckets;
  74. CTableElement *_last;
  75. };
  76. #endif // __GENERIC_TABLE_HXX