forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2/N][VirtualClusetr] add GcsVirtualClusterTable
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2017 The Ray Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "ray/common/id.h" | ||
|
||
namespace ray { | ||
|
||
template <typename T> | ||
struct SimpleID { | ||
static T FromBinary(const std::string &binary) { | ||
T id; | ||
id.id_ = binary; | ||
return id; | ||
} | ||
|
||
size_t Hash() const { | ||
// Note(ashione): hash code lazy calculation(it's invoked every time if hash code is | ||
// default value 0) | ||
if (!hash_) { | ||
hash_ = MurmurHash64A(id_.data(), id_.size(), 0); | ||
} | ||
return hash_; | ||
} | ||
|
||
const std::string &Binary() const { return id_; } | ||
|
||
bool operator==(const T &rhs) const { return id_ == rhs.id_; } | ||
bool operator!=(const T &rhs) const { return !(*this == rhs); } | ||
|
||
private: | ||
std::string id_; | ||
mutable size_t hash_ = 0; | ||
}; | ||
|
||
} // namespace ray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2017 The Ray Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "ray/common/simple_id.h" | ||
|
||
namespace ray { | ||
|
||
class VirtualClusterID : public SimpleID<VirtualClusterID> { | ||
using SimpleID::SimpleID; | ||
}; | ||
|
||
inline std::ostream &operator<<(std::ostream &os, const ray::VirtualClusterID &id) { | ||
os << id.Binary(); | ||
return os; | ||
} | ||
|
||
} // namespace ray | ||
|
||
namespace std { | ||
|
||
template <> | ||
struct hash<ray::VirtualClusterID> { | ||
size_t operator()(const ray::VirtualClusterID &id) const { return id.Hash(); } | ||
}; | ||
template <> | ||
struct hash<const ray::VirtualClusterID> { | ||
size_t operator()(const ray::VirtualClusterID &id) const { return id.Hash(); } | ||
}; | ||
|
||
} // namespace std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters