StringHash.pkg 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. $#include "StringHash.h"
  2. /// 32-bit hash value for a string.
  3. class StringHash
  4. {
  5. public:
  6. /// Construct with zero value.
  7. StringHash();
  8. /// Copy-construct from another hash.
  9. StringHash(const StringHash& rhs);
  10. /// Construct with an initial value.
  11. explicit StringHash(unsigned value);
  12. /// Construct from a C string case-insensitively.
  13. StringHash(const char* str);
  14. /// Construct from a string case-insensitively.
  15. StringHash(const String& str);
  16. /// Add a hash.
  17. StringHash operator + (const StringHash& rhs) const;
  18. // Test for equality with another hash.
  19. bool operator == (const StringHash& rhs) const;
  20. /// Test if less than another hash.
  21. bool operator < (const StringHash& rhs) const;
  22. /// Return hash value.
  23. unsigned Value() const;
  24. /// Calculate hash value case-insensitively from a C string.
  25. static unsigned Calculate(const char* str);
  26. /// Zero hash.
  27. static const StringHash ZERO;
  28. };
  29. /// 16-bit hash value for a string.
  30. class ShortStringHash
  31. {
  32. public:
  33. /// Construct with zero hash value.
  34. ShortStringHash();
  35. /// Copy-construct from another hash value.
  36. ShortStringHash(const ShortStringHash& rhs);
  37. /// Copy-construct from another 32-bit hash value (ignore the high bits.)
  38. explicit ShortStringHash(const StringHash& rhs);
  39. /// Construct with an initial value.
  40. explicit ShortStringHash(unsigned short value);
  41. /// Construct from a C string case-insensitively.
  42. ShortStringHash(const char* str);
  43. /// Construct from a string case-insensitively.
  44. ShortStringHash(const String& str);
  45. /// Add a hash.
  46. ShortStringHash operator + (const ShortStringHash& rhs) const;
  47. /// Test for equality with another hash.
  48. bool operator == (const ShortStringHash& rhs) const;
  49. /// Test if less than another hash.
  50. bool operator < (const ShortStringHash& rhs) const;
  51. /// Return hash value.
  52. unsigned short Value() const { return value_; }
  53. /// Calculate hash value case-insensitively from a C string.
  54. static unsigned short Calculate(const char* str);
  55. /// Zero hash.
  56. static const ShortStringHash ZERO;
  57. };