cmPathLabel.cxx 880 B

123456789101112131415161718192021222324252627282930
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmPathLabel.h"
  4. #include <stddef.h>
  5. cmPathLabel::cmPathLabel(const std::string& label)
  6. : Label(label)
  7. , Hash(0)
  8. {
  9. // Use a Jenkins one-at-a-time hash with under/over-flow protection
  10. for (size_t i = 0; i < this->Label.size(); ++i) {
  11. this->Hash += this->Label[i];
  12. this->Hash += ((this->Hash & 0x003FFFFF) << 10);
  13. this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
  14. }
  15. this->Hash += ((this->Hash & 0x1FFFFFFF) << 3);
  16. this->Hash ^= ((this->Hash & 0xFFFFF800) >> 11);
  17. this->Hash += ((this->Hash & 0x0001FFFF) << 15);
  18. }
  19. bool cmPathLabel::operator<(const cmPathLabel& l) const
  20. {
  21. return this->Hash < l.Hash;
  22. }
  23. bool cmPathLabel::operator==(const cmPathLabel& l) const
  24. {
  25. return this->Hash == l.Hash;
  26. }