1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, Andres Noetzli |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Implements an n-ary match trie |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__EXPR__NARY_MATCH_TRIE_H |
19 |
|
#define CVC5__EXPR__NARY_MATCH_TRIE_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
#include <vector> |
23 |
|
|
24 |
|
#include "expr/match_trie.h" |
25 |
|
#include "expr/node.h" |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
namespace expr { |
29 |
|
|
30 |
|
/** |
31 |
|
* A trie used for matching n-ary terms. We use the null node as a terminator |
32 |
|
* when adding terms to this trie to signify the end of n-ary symbols. |
33 |
|
* |
34 |
|
* For example: |
35 |
|
* Adding the terms (or a b c), (or a b), (or a a) would create this index: |
36 |
|
* |
37 |
|
* OR |
38 |
|
* a |
39 |
|
* a |
40 |
|
* null -> (or a a) |
41 |
|
* b |
42 |
|
* c |
43 |
|
* null -> (or a b c) |
44 |
|
* null -> (or a b) |
45 |
|
*/ |
46 |
|
class NaryMatchTrie |
47 |
|
{ |
48 |
|
public: |
49 |
|
/** Get matches |
50 |
|
* |
51 |
|
* This calls ntm->notify( n, s, vars, subs ) for each term s stored in this |
52 |
|
* trie that is matchable with n where s = n * { vars -> subs } for some |
53 |
|
* vars, subs, where * has list semantics for substitution (see |
54 |
|
* listSubstitute in expr/nary_term_util.h). |
55 |
|
* |
56 |
|
* This function returns false if one of these calls to notify |
57 |
|
* returns false. |
58 |
|
*/ |
59 |
|
bool getMatches(Node n, NotifyMatch* ntm) const; |
60 |
|
/** Adds node n to this trie */ |
61 |
|
void addTerm(Node n); |
62 |
|
/** Clear this trie */ |
63 |
|
void clear(); |
64 |
|
/** debug print */ |
65 |
|
std::string debugPrint() const; |
66 |
|
|
67 |
|
private: |
68 |
|
/** |
69 |
|
* The children of this node in the trie. Terms t are indexed by a |
70 |
|
* depth-first (right to left) traversal on its subterms, where the |
71 |
|
* top-symbol of t is indexed by: |
72 |
|
* - operator, if t has an operator, or |
73 |
|
* - t, if t does not have an operator |
74 |
|
* Additionally we use "null" to mark the end of applications of n-ary |
75 |
|
* symbols. |
76 |
|
*/ |
77 |
|
std::map<Node, NaryMatchTrie> d_children; |
78 |
|
/** The set of variables in the domain of d_children */ |
79 |
|
std::vector<Node> d_vars; |
80 |
|
/** The data of this node in the trie */ |
81 |
|
Node d_data; |
82 |
|
}; |
83 |
|
|
84 |
|
} // namespace expr |
85 |
|
} // namespace cvc5 |
86 |
|
|
87 |
|
#endif /* CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_FILTER_H */ |