static*/
| 346 | |
| 347 | template <typename FunctionTy> |
| 348 | /*static*/ void Predicate::Visit(Predicate* p, const FunctionTy& func) { |
| 349 | absl::flat_hash_set<Predicate*> visited; |
| 350 | std::vector<Predicate*> stack; |
| 351 | |
| 352 | stack.push_back(p); |
| 353 | visited.insert(p); |
| 354 | |
| 355 | while (!stack.empty()) { |
| 356 | Predicate* current = stack.back(); |
| 357 | stack.pop_back(); |
| 358 | bool done = func(current); |
| 359 | if (done) { |
| 360 | return; |
| 361 | } |
| 362 | for (Predicate* op : current->GetOperands()) { |
| 363 | if (visited.insert(op).second) { |
| 364 | stack.push_back(op); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | // Creates and owns Predicate instances. Simplifies predicates as it creates |
| 371 | // them. |