2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2014-10-17 17:07:26 +00:00
|
|
|
#include "cmPathLabel.h"
|
|
|
|
|
2016-11-05 20:40:14 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2014-10-17 17:07:26 +00:00
|
|
|
cmPathLabel::cmPathLabel(const std::string& label)
|
2016-05-16 14:34:04 +00:00
|
|
|
: Label(label)
|
|
|
|
, Hash(0)
|
2014-10-17 17:07:26 +00:00
|
|
|
{
|
|
|
|
// Use a Jenkins one-at-a-time hash with under/over-flow protection
|
2016-05-16 14:34:04 +00:00
|
|
|
for (size_t i = 0; i < this->Label.size(); ++i) {
|
2014-10-17 17:07:26 +00:00
|
|
|
this->Hash += this->Label[i];
|
|
|
|
this->Hash += ((this->Hash & 0x003FFFFF) << 10);
|
|
|
|
this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-10-17 17:07:26 +00:00
|
|
|
this->Hash += ((this->Hash & 0x1FFFFFFF) << 3);
|
|
|
|
this->Hash ^= ((this->Hash & 0xFFFFF800) >> 11);
|
|
|
|
this->Hash += ((this->Hash & 0x0001FFFF) << 15);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmPathLabel::operator<(const cmPathLabel& l) const
|
2014-10-17 17:07:26 +00:00
|
|
|
{
|
|
|
|
return this->Hash < l.Hash;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmPathLabel::operator==(const cmPathLabel& l) const
|
2014-10-17 17:07:26 +00:00
|
|
|
{
|
|
|
|
return this->Hash == l.Hash;
|
|
|
|
}
|