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.

81 lines
1.7 KiB

  1. #include <lkrhash.h>
  2. #ifndef __LKRHASH_NO_NAMESPACE__
  3. using namespace LKRhash;
  4. #endif // __LKRHASH_NO_NAMESPACE__
  5. #ifndef __HASHFN_NO_NAMESPACE__
  6. using namespace HashFn;
  7. #endif // __HASHFN_NO_NAMESPACE__
  8. class VwrecordBase
  9. {
  10. public:
  11. VwrecordBase(const char* pszKey, int i)
  12. {
  13. Key = new char[strlen(pszKey) + 1];
  14. strcpy(Key, pszKey);
  15. m_num = i;
  16. cRef = 0;
  17. }
  18. virtual ~VwrecordBase()
  19. {
  20. // printf("~VwrecordBase: %s\n", Key);
  21. delete [] Key;
  22. }
  23. char* getKey() const { return Key; }
  24. LONG AddRefRecord(LK_ADDREF_REASON lkar) const
  25. {
  26. LONG l;
  27. if (lkar > 0)
  28. l = InterlockedIncrement(&cRef);
  29. else if ((l = InterlockedDecrement(&cRef)) == 0)
  30. delete this;
  31. return l;
  32. }
  33. private:
  34. char* Key;
  35. int m_num;
  36. mutable long cRef;
  37. };
  38. // a hashtable of read-only VwrecordBases, using strings as the key.
  39. class CWcharHashTable
  40. : public CTypedHashTable<CWcharHashTable, const VwrecordBase, const char*>
  41. {
  42. public:
  43. CWcharHashTable()
  44. : CTypedHashTable<CWcharHashTable, const VwrecordBase, const char*>("VWtest")
  45. {}
  46. static char*
  47. ExtractKey(const VwrecordBase* pRecord)
  48. {
  49. return pRecord->getKey();
  50. }
  51. static DWORD
  52. CalcKeyHash(const char* pszKey)
  53. {
  54. return HashString(pszKey);
  55. }
  56. static int
  57. CompareKeys(const char* pszKey1, const char* pszKey2)
  58. {
  59. return strcmp(pszKey1, pszKey2);
  60. }
  61. static LONG
  62. AddRefRecord(const VwrecordBase* pRecord, LK_ADDREF_REASON lkar)
  63. {
  64. return pRecord->AddRefRecord(lkar);
  65. }
  66. };