Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Implements a match trie, also known as a discrimination tree. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__EXPR__MATCH_TRIE_H 16 : : #define CVC5__EXPR__MATCH_TRIE_H 17 : : 18 : : #include <map> 19 : : #include <vector> 20 : : 21 : : #include "expr/node.h" 22 : : 23 : : namespace cvc5::internal { 24 : : namespace expr { 25 : : 26 : : /** A virtual class for notifications regarding matches. */ 27 : : class NotifyMatch 28 : : { 29 : : public: 30 : 13294 : virtual ~NotifyMatch() {} 31 : : /** 32 : : * A notification that s is equal to n * { vars -> subs }. This function 33 : : * should return false if we do not wish to be notified of further matches. 34 : : */ 35 : : virtual bool notify(Node s, 36 : : Node n, 37 : : std::vector<Node>& vars, 38 : : std::vector<Node>& subs) = 0; 39 : : }; 40 : : 41 : : /** 42 : : * A trie (discrimination tree) storing a set of terms S, that can be used to 43 : : * query, for a given term t, all terms s from S that are matchable with t, 44 : : * that is s*sigma = t for some substitution sigma. 45 : : */ 46 : : class MatchTrie 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. This function returns false if one of these calls to notify 54 : : * returns false. 55 : : */ 56 : : bool getMatches(Node n, NotifyMatch* ntm); 57 : : /** Adds node n to this trie */ 58 : : void addTerm(Node n); 59 : : /** Clear this trie */ 60 : : void clear(); 61 : : 62 : : private: 63 : : /** 64 : : * The children of this node in the trie. Terms t are indexed by a 65 : : * depth-first (right to left) traversal on its subterms, where the 66 : : * top-symbol of t is indexed by: 67 : : * - (operator, #children) if t has an operator, or 68 : : * - (t, 0) if t does not have an operator. 69 : : */ 70 : : std::map<Node, std::map<unsigned, MatchTrie> > d_children; 71 : : /** The set of variables in the domain of d_children */ 72 : : std::vector<Node> d_vars; 73 : : /** The data of this node in the trie */ 74 : : Node d_data; 75 : : }; 76 : : 77 : : } // namespace expr 78 : : } // namespace cvc5::internal 79 : : 80 : : #endif /* CVC5__THEORY__QUANTIFIERS__CANDIDATE_REWRITE_FILTER_H */