Simplify hashing of rules
This commit is contained in:
parent
5c1a0982df
commit
a63624f2aa
12 changed files with 29 additions and 15 deletions
|
|
@ -51,7 +51,7 @@ namespace std {
|
|||
size_t operator()(const tree_sitter::build_tables::Item &item) const {
|
||||
return
|
||||
hash<tree_sitter::rules::Symbol>()(item.lhs) ^
|
||||
hash<tree_sitter::rules::Rule>()(*item.rule);
|
||||
hash<tree_sitter::rules::rule_ptr>()(item.rule);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ namespace std {
|
|||
size_t operator()(const tree_sitter::build_tables::ParseItem &item) const {
|
||||
return
|
||||
hash<string>()(item.lhs.name) ^
|
||||
hash<tree_sitter::rules::Rule>()(*item.rule) ^
|
||||
hash<tree_sitter::rules::rule_ptr>()(item.rule) ^
|
||||
hash<size_t>()(item.consumed_symbols.size()) ^
|
||||
hash<string>()(item.lookahead_sym.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Blank::hash_code() const {
|
||||
return typeid(this).hash_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rule_ptr Blank::copy() const {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,12 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t CharacterSet::hash_code() const {
|
||||
return typeid(this).hash_code() ^ hash<string>()(to_string());
|
||||
size_t result = std::hash<size_t>()(ranges.size());
|
||||
for (auto &range : ranges) {
|
||||
result ^= std::hash<char>()(range.min);
|
||||
result ^= std::hash<char>()(range.max);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
rule_ptr CharacterSet::copy() const {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,11 @@ namespace tree_sitter {
|
|||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<tree_sitter::rules::CharacterSet> : hash<tree_sitter::rules::Rule> {};
|
||||
struct hash<tree_sitter::rules::CharacterSet> {
|
||||
size_t operator()(const tree_sitter::rules::CharacterSet &rule) const {
|
||||
return rule.hash_code();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Choice::hash_code() const {
|
||||
return typeid(this).hash_code() ^ left->hash_code() ^ right->hash_code();
|
||||
return left->hash_code() ^ right->hash_code();
|
||||
}
|
||||
|
||||
rule_ptr Choice::copy() const {
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Pattern::hash_code() const {
|
||||
return typeid(this).hash_code() ^ hash<string>()(value);
|
||||
return hash<string>()(value);
|
||||
}
|
||||
|
||||
rule_ptr Pattern::copy() const {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Repeat::hash_code() const {
|
||||
return typeid(this).hash_code() ^ content->hash_code();
|
||||
return content->hash_code();
|
||||
}
|
||||
|
||||
rule_ptr Repeat::copy() const {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ namespace tree_sitter {
|
|||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<tree_sitter::rules::Rule> {
|
||||
size_t operator()(const tree_sitter::rules::Rule &rule) const {
|
||||
return rule.hash_code();
|
||||
struct hash<tree_sitter::rules::rule_ptr> {
|
||||
size_t operator()(const tree_sitter::rules::rule_ptr &rule) const {
|
||||
return typeid(*rule).hash_code() ^ rule->hash_code();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Seq::hash_code() const {
|
||||
return typeid(this).hash_code() ^ left->hash_code() ^ right->hash_code();
|
||||
return left->hash_code() ^ right->hash_code();
|
||||
}
|
||||
|
||||
rule_ptr Seq::copy() const {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t String::hash_code() const {
|
||||
return typeid(this).hash_code() ^ hash<string>()(value);
|
||||
return hash<string>()(value);
|
||||
}
|
||||
|
||||
rule_ptr String::copy() const {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace tree_sitter {
|
|||
}
|
||||
|
||||
size_t Symbol::hash_code() const {
|
||||
return typeid(this).hash_code() ^ hash<string>()(name) ^ hash<bool>()(is_auxiliary);
|
||||
return hash<string>()(name) ^ hash<bool>()(is_auxiliary);
|
||||
}
|
||||
|
||||
rule_ptr Symbol::copy() const {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define __tree_sitter__sym__
|
||||
|
||||
#include "rule.h"
|
||||
#include <map>
|
||||
|
||||
namespace tree_sitter {
|
||||
namespace rules {
|
||||
|
|
@ -27,7 +28,11 @@ namespace tree_sitter {
|
|||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<tree_sitter::rules::Symbol> : hash<tree_sitter::rules::Rule> {};
|
||||
struct hash<tree_sitter::rules::Symbol> {
|
||||
size_t operator()(const tree_sitter::rules::Symbol &rule) const {
|
||||
return rule.hash_code();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue