perf(name): add quick_cmp for hierarchical names

It first compare names using hash codes.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-10-25 09:58:01 -07:00
parent 66f4834dbc
commit 2b5c951de3
2 changed files with 21 additions and 4 deletions

View file

@ -19,7 +19,7 @@ namespace lean {
metavariables to expressions.
*/
class substitution {
typedef splay_map<name, expr, name_cmp> name2expr;
typedef splay_map<name, expr, name_quick_cmp> name2expr;
name2expr m_subst;
unsigned m_size;
// If the following flag is true, then beta-reduction is automatically applied
@ -99,9 +99,9 @@ void swap(substitution & s1, substitution & s2);
4- Collecting constraints
*/
class metavar_env {
typedef splay_map<name, expr, name_cmp> name2expr;
typedef splay_map<name, context, name_cmp> name2context;
typedef splay_map<name, justification, name_cmp> name2justification;
typedef splay_map<name, expr, name_quick_cmp> name2expr;
typedef splay_map<name, context, name_quick_cmp> name2context;
typedef splay_map<name, justification, name_quick_cmp> name2justification;
name_generator m_name_generator;
substitution m_substitution;

View file

@ -99,8 +99,25 @@ public:
friend void swap(name & a, name & b) {
std::swap(a.m_ptr, b.m_ptr);
}
/**
\brief Quicker version of \c cmp that uses the hashcode.
Remark: we should not use it when we want to order names using
lexicographical order.
*/
friend int quick_cmp(name const & a, name const & b) {
if (a.m_ptr == b.m_ptr)
return 0;
unsigned h1 = a.hash();
unsigned h2 = b.hash();
if (h1 != h2)
return h1 < h2 ? -1 : 1;
else
return cmp(a, b);
}
};
struct name_hash { unsigned operator()(name const & n) const { return n.hash(); } };
struct name_eq { bool operator()(name const & n1, name const & n2) const { return n1 == n2; } };
struct name_cmp { int operator()(name const & n1, name const & n2) const { return cmp(n1, n2); } };
struct name_quick_cmp { int operator()(name const & n1, name const & n2) const { return quick_cmp(n1, n2); } };
}