| 363 | */ |
| 364 | template<typename BS> |
| 365 | DepGraph<BS> BuildTreeGraph(const DepGraph<BS>& depgraph, uint8_t direction) |
| 366 | { |
| 367 | DepGraph<BS> depgraph_tree; |
| 368 | for (DepGraphIndex i = 0; i < depgraph.PositionRange(); ++i) { |
| 369 | if (depgraph.Positions()[i]) { |
| 370 | depgraph_tree.AddTransaction(depgraph.FeeRate(i)); |
| 371 | } else { |
| 372 | // For holes, add a dummy transaction which is deleted below, so that non-hole |
| 373 | // transactions retain their position. |
| 374 | depgraph_tree.AddTransaction(FeeFrac{}); |
| 375 | } |
| 376 | } |
| 377 | depgraph_tree.RemoveTransactions(BS::Fill(depgraph.PositionRange()) - depgraph.Positions()); |
| 378 | |
| 379 | if (direction & 1) { |
| 380 | for (DepGraphIndex i : depgraph.Positions()) { |
| 381 | auto children = depgraph.GetReducedChildren(i); |
| 382 | if (children.Any()) { |
| 383 | depgraph_tree.AddDependencies(BS::Singleton(i), children.First()); |
| 384 | } |
| 385 | } |
| 386 | } else { |
| 387 | for (DepGraphIndex i : depgraph.Positions()) { |
| 388 | auto parents = depgraph.GetReducedParents(i); |
| 389 | if (parents.Any()) { |
| 390 | depgraph_tree.AddDependencies(BS::Singleton(parents.First()), i); |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | return depgraph_tree; |
| 396 | } |
| 397 | |
| 398 | } // namespace |
| 399 |
no test coverage detected