Chromium Code Reviews| Index: services/resource_coordinator/public/cpp/coordination_unit_id.cc |
| diff --git a/services/resource_coordinator/public/cpp/coordination_unit_id.cc b/services/resource_coordinator/public/cpp/coordination_unit_id.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..634b35a03c63f4ddb92e1a8edda3704424a0b118 |
| --- /dev/null |
| +++ b/services/resource_coordinator/public/cpp/coordination_unit_id.cc |
| @@ -0,0 +1,27 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "services/resource_coordinator/public/cpp/coordination_unit_id.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/numerics/safe_conversions.h" |
| +#include "third_party/smhasher/src/MurmurHash2.h" |
|
nasko
2017/04/21 00:17:32
Doesn't std::hash suffice here?
oystein (OOO til 10th of July)
2017/04/21 17:57:55
I had that originally as well, primiano in #2 sugg
nasko
2017/04/24 22:10:50
Acknowledged.
|
| + |
| +namespace resource_coordinator { |
| + |
| +// The seed to use when taking the murmur2 hash of the id. |
| +const uint64_t kMurmur2HashSeed = 0; |
| + |
| +CoordinationUnitID::CoordinationUnitID() |
| + : id(0), type(CoordinationUnitType::INVALID_TYPE) {} |
| + |
| +CoordinationUnitID::CoordinationUnitID(const CoordinationUnitType& type, |
| + const std::string& new_id) |
|
nasko
2017/04/21 00:17:32
Let's keep the parameter names in sync between hea
oystein (OOO til 10th of July)
2017/04/21 17:57:55
Done.
|
| + : type(type) { |
| + DCHECK(base::IsValueInRangeForNumericType<int>(new_id.size())); |
| + id = MurmurHash2(&new_id.front(), static_cast<int>(new_id.size()), |
| + kMurmur2HashSeed); |
| +} |
| + |
| +} // resource_coordinator |