Skip to content

Commit

Permalink
add optional header and hashlib implementation for optional
Browse files Browse the repository at this point in the history
  • Loading branch information
aiju committed Jul 25, 2024
1 parent 97d2e5d commit 21d6f96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ template<typename... T> struct hash_ops<std::variant<T...>> {
}
};

template<typename T> struct hash_ops<std::optional<T>> {
static inline bool cmp(std::optional<T> a, std::optional<T> b) {
return a == b;
}
static inline unsigned int hash(std::optional<T> a) {
if(a.has_value())
return mkhash(*a);
else
return 0;
}
};

inline int hashtable_size(int min_size)
{
static std::vector<int> zero_and_some_primes = {
Expand Down
1 change: 1 addition & 0 deletions kernel/yosys_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unordered_set>
#include <initializer_list>
#include <variant>
#include <optional>
#include <stdexcept>
#include <memory>
#include <cmath>
Expand Down

0 comments on commit 21d6f96

Please sign in to comment.