cmPathLabel.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmPathLabel.h"
  11. //----------------------------------------------------------------------------
  12. cmPathLabel::cmPathLabel(const std::string& label)
  13. : Label(label), Hash(0)
  14. {
  15. // Use a Jenkins one-at-a-time hash with under/over-flow protection
  16. for(size_t i = 0; i < this->Label.size(); ++i)
  17. {
  18. this->Hash += this->Label[i];
  19. this->Hash += ((this->Hash & 0x003FFFFF) << 10);
  20. this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
  21. }
  22. this->Hash += ((this->Hash & 0x1FFFFFFF) << 3);
  23. this->Hash ^= ((this->Hash & 0xFFFFF800) >> 11);
  24. this->Hash += ((this->Hash & 0x0001FFFF) << 15);
  25. }
  26. //----------------------------------------------------------------------------
  27. bool cmPathLabel::operator < (const cmPathLabel& l) const
  28. {
  29. return this->Hash < l.Hash;
  30. }
  31. //----------------------------------------------------------------------------
  32. bool cmPathLabel::operator == (const cmPathLabel& l) const
  33. {
  34. return this->Hash == l.Hash;
  35. }