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 : : * Algorithms for node tries 11 : : */ 12 : : 13 : : #include "expr/node_trie_algorithm.h" 14 : : 15 : : namespace cvc5::internal { 16 : : 17 : 140114 : void nodeTriePathPairProcess(const TNodeTrie* t, 18 : : size_t arity, 19 : : NodeTriePathPairProcessCallback& ntpc) 20 : : { 21 : 140114 : std::vector<std::tuple<const TNodeTrie*, const TNodeTrie*, size_t>> visit; 22 : 140114 : std::tuple<const TNodeTrie*, const TNodeTrie*, size_t> cur; 23 : : const TNodeTrie* t1; 24 : : const TNodeTrie* t2; 25 : : size_t depth; 26 : 140114 : visit.emplace_back(t, nullptr, 0); 27 : : do 28 : : { 29 : 1122664 : cur = visit.back(); 30 : 1122664 : t1 = std::get<0>(cur); 31 : 1122664 : t2 = std::get<1>(cur); 32 : 1122664 : depth = std::get<2>(cur); 33 : 1122664 : visit.pop_back(); 34 [ + + ]: 1122664 : if (depth == arity) 35 : : { 36 : : // We are at the leaves. If we split the path, process the data. 37 [ + - ]: 523399 : if (t2 != nullptr) 38 : : { 39 : 523399 : ntpc.processData(t1->getData(), t2->getData()); 40 : : } 41 : : } 42 [ + + ]: 599265 : else if (t2 == nullptr) 43 : : { 44 : : // we are exploring paths with a common prefix 45 [ + + ]: 257626 : if (depth < (arity - 1)) 46 : : { 47 : : // continue exploring paths with common prefix, internal to each child 48 [ + + ]: 184258 : for (const std::pair<const TNode, TNodeTrie>& tt : t1->d_data) 49 : : { 50 : 117512 : visit.emplace_back(&tt.second, nullptr, depth + 1); 51 : : } 52 : : } 53 : : // consider splitting the path at this node 54 : 257626 : for (std::map<TNode, TNodeTrie>::const_iterator it = t1->d_data.begin(); 55 [ + + ]: 1172724 : it != t1->d_data.end(); 56 : 915098 : ++it) 57 : : { 58 : 915098 : std::map<TNode, TNodeTrie>::const_iterator it2 = it; 59 : 915098 : ++it2; 60 [ + + ]: 6036769 : for (; it2 != t1->d_data.end(); ++it2) 61 : : { 62 [ + + ]: 5121671 : if (ntpc.considerPath(it->first, it2->first)) 63 : : { 64 : 619632 : visit.emplace_back(&it->second, &it2->second, depth + 1); 65 : : } 66 : : } 67 : : } 68 : : } 69 : : else 70 : : { 71 [ - + ][ - + ]: 341639 : Assert(t1 != t2); [ - - ] 72 : : // considering two different paths, take the product of their children 73 [ + + ]: 886041 : for (const std::pair<const TNode, TNodeTrie>& tt1 : t1->d_data) 74 : : { 75 [ + + ]: 1233320 : for (const std::pair<const TNode, TNodeTrie>& tt2 : t2->d_data) 76 : : { 77 [ + + ]: 688918 : if (ntpc.considerPath(tt1.first, tt2.first)) 78 : : { 79 : 245406 : visit.emplace_back(&tt1.second, &tt2.second, depth + 1); 80 : : } 81 : : } 82 : : } 83 : : } 84 [ + + ]: 1122664 : } while (!visit.empty()); 85 : 140114 : } 86 : : 87 : : } // namespace cvc5::internal