refactor(library/congr_lemma_manager): move expr_unsigned_map to separate module

This commit is contained in:
Leonardo de Moura 2016-01-06 17:29:16 -08:00
parent 43c5cbd1bf
commit 7312dd77b8
2 changed files with 41 additions and 22 deletions

View file

@ -12,6 +12,7 @@ Author: Leonardo de Moura
#include "library/constants.h"
#include "library/replace_visitor.h"
#include "library/relation_manager.h"
#include "library/expr_unsigned_map.h"
#include "library/congr_lemma_manager.h"
namespace lean {
@ -24,28 +25,12 @@ struct congr_lemma_manager::imp {
app_builder & m_builder;
fun_info_manager & m_fmanager;
type_context & m_ctx;
struct key {
expr m_fn;
unsigned m_nargs;
unsigned m_hash;
key(expr const & fn, unsigned nargs):
m_fn(fn), m_nargs(nargs), m_hash(hash(m_fn.hash(), m_nargs)) {}
};
struct key_hash_fn {
unsigned operator()(key const & k) const { return k.m_hash; }
};
struct key_eq_fn {
bool operator()(key const & k1, key const & k2) const {
return k1.m_fn == k2.m_fn && k1.m_nargs == k2.m_nargs;
}
};
std::unordered_map<key, result, key_hash_fn, key_eq_fn> m_simp_cache;
std::unordered_map<key, result, key_hash_fn, key_eq_fn> m_cache;
std::unordered_map<key, result, key_hash_fn, key_eq_fn> m_rel_cache[2];
relation_info_getter m_relation_info_getter;
typedef expr_unsigned key;
typedef expr_unsigned_map<result> cache;
cache m_simp_cache;
cache m_cache;
cache m_rel_cache[2];
relation_info_getter m_relation_info_getter;
expr infer(expr const & e) { return m_ctx.infer(e); }
expr whnf(expr const & e) { return m_ctx.whnf(e); }

View file

@ -0,0 +1,34 @@
/*
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#pragma once
#include <unordered_map>
#include "kernel/expr.h"
namespace lean {
/* pair (expression, unsigned int) with cached hash code */
struct expr_unsigned {
expr m_expr;
unsigned m_nargs;
unsigned m_hash;
expr_unsigned(expr const & fn, unsigned nargs):
m_expr(fn), m_nargs(nargs), m_hash(hash(m_expr.hash(), m_nargs)) {}
};
struct expr_unsigned_hash_fn {
unsigned operator()(expr_unsigned const & k) const { return k.m_hash; }
};
struct expr_unsigned_eq_fn {
bool operator()(expr_unsigned const & k1, expr_unsigned const & k2) const {
return k1.m_expr == k2.m_expr && k1.m_nargs == k2.m_nargs;
}
};
/* mapping from (expr, unsigned) -> T */
template<typename T>
using expr_unsigned_map = typename std::unordered_map<expr_unsigned, T, expr_unsigned_hash_fn, expr_unsigned_eq_fn>;
}