-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ir] Add struct type to CHI-IR (#6982)
Issue: #6983 ### Brief Summary Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
59d8909
commit 449a7f6
Showing
7 changed files
with
146 additions
and
1 deletion.
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
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
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,36 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <stddef.h> | ||
|
||
namespace taichi::hashing { | ||
|
||
template <typename T> | ||
struct Hasher { | ||
public: | ||
size_t operator()(T const &val) const { | ||
return std::hash<T>{}(val); | ||
} | ||
}; | ||
|
||
namespace { | ||
template <typename T> | ||
inline void hash_combine(size_t &seed, T const &value) { | ||
// Reference: | ||
// https://www.boost.org/doc/libs/1_55_0/doc/html/hash/reference.html#boost.hash_combine | ||
seed ^= Hasher<T>{}(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | ||
} | ||
} // namespace | ||
|
||
template <typename T> | ||
struct Hasher<std::vector<T>> { | ||
public: | ||
size_t operator()(std::vector<T> const &vec) const { | ||
size_t ret = 0; | ||
for (const auto &i : vec) { | ||
hash_combine(ret, i); | ||
} | ||
return ret; | ||
} | ||
}; | ||
} // namespace taichi::hashing |