cmake/Source/cmPathLabel.cxx

31 lines
849 B
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-04-27 22:25:09 +02:00
#include "cmPathLabel.h"
2019-11-11 23:01:05 +01:00
#include <utility>
cmPathLabel::cmPathLabel(std::string label)
: Label(std::move(label))
2016-07-09 11:21:54 +02:00
, Hash(0)
2015-04-27 22:25:09 +02:00
{
// Use a Jenkins one-at-a-time hash with under/over-flow protection
2018-01-26 17:06:56 +01:00
for (char i : this->Label) {
this->Hash += i;
2015-04-27 22:25:09 +02:00
this->Hash += ((this->Hash & 0x003FFFFF) << 10);
this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
this->Hash += ((this->Hash & 0x1FFFFFFF) << 3);
this->Hash ^= ((this->Hash & 0xFFFFF800) >> 11);
this->Hash += ((this->Hash & 0x0001FFFF) << 15);
}
2016-07-09 11:21:54 +02:00
bool cmPathLabel::operator<(const cmPathLabel& l) const
2015-04-27 22:25:09 +02:00
{
return this->Hash < l.Hash;
}
2016-07-09 11:21:54 +02:00
bool cmPathLabel::operator==(const cmPathLabel& l) const
2015-04-27 22:25:09 +02:00
{
return this->Hash == l.Hash;
}