Source code of Windows XP (NT5)
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.

78 lines
1.4 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. void AddRefRecord(LK_ADDREF_REASON lkar) const
  25. {
  26. if (lkar > 0)
  27. InterlockedIncrement(&cRef);
  28. else if (InterlockedDecrement(&cRef) == 0)
  29. delete this;
  30. }
  31. private:
  32. char* Key;
  33. int m_num;
  34. mutable long cRef;
  35. };
  36. class CWcharHashTable
  37. : public CTypedHashTable<CWcharHashTable, const VwrecordBase, char*>
  38. {
  39. public:
  40. CWcharHashTable()
  41. : CTypedHashTable<CWcharHashTable, const VwrecordBase, char*>("VWtest")
  42. {}
  43. static char*
  44. ExtractKey(const VwrecordBase* pRecord)
  45. {
  46. return pRecord->getKey();
  47. }
  48. static DWORD
  49. CalcKeyHash(const char* pszKey)
  50. {
  51. return HashString(pszKey);
  52. }
  53. static bool
  54. EqualKeys(const char* pszKey1, const char* pszKey2)
  55. {
  56. return (strcmp(pszKey1, pszKey2) == 0);
  57. }
  58. static void
  59. AddRefRecord(const VwrecordBase* pRecord, LK_ADDREF_REASON lkar)
  60. {
  61. pRecord->AddRefRecord(lkar);
  62. }
  63. };