forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpr_cache.cpp
More file actions
33 lines (29 loc) · 817 Bytes
/
expr_cache.cpp
File metadata and controls
33 lines (29 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "kernel/expr_cache.h"
namespace lean {
expr * expr_cache::find(expr const & e) {
unsigned i = hash(e) % m_capacity;
if (m_cache[i].m_expr && is_bi_equal(*m_cache[i].m_expr, e))
return &m_cache[i].m_result;
else
return nullptr;
}
void expr_cache::insert(expr const & e, expr const & v) {
unsigned i = hash(e) % m_capacity;
if (!m_cache[i].m_expr)
m_used.push_back(i);
m_cache[i].m_expr = e;
m_cache[i].m_result = v;
}
void expr_cache::clear() {
for (unsigned i : m_used) {
m_cache[i].m_expr = none_expr();
m_cache[i].m_result = expr();
}
m_used.clear();
}
}