Lattice Land Powerdomains Library
Loading...
Searching...
No Matches
light_branch.hpp
Go to the documentation of this file.
1// Copyright 2025 Pierre Talbot
2
3#ifndef LALA_POWER_LIGHT_BRANCH_HPP
4#define LALA_POWER_LIGHT_BRANCH_HPP
5
6/** Similar to `Branch` but specialized to binary search tree splitting over universe (e.g. interval). */
7
8namespace lala {
9
10template <class U>
12 template <class U2>
13 friend class LightBranch;
14
15 AVar var;
17 /** Ropes are used for fast backtracking: `ropes[1]` is the depth we need to backtrack to if the right node is a leaf. */
18 int ropes[2];
20
21 CUDA INLINE LightBranch(): current_idx(-1) {}
22 LightBranch(const LightBranch&) = default;
24 CUDA INLINE LightBranch(AVar var, const U& left, const U& right)
25 : var(var), current_idx(-1)
26 {
27 children[0] = left;
28 children[1] = right;
29 }
30
31 CUDA INLINE const U& next() {
32 assert(has_next());
33 return children[++current_idx];
34 }
35
36 CUDA INLINE const U& operator[](int idx) {
37 return children[idx];
38 }
39
40 CUDA INLINE bool has_next() const {
41 return current_idx < 1;
42 }
43
44 CUDA INLINE void prune() {
45 current_idx = 2;
46 }
47
48 CUDA INLINE bool is_pruned() const {
49 return current_idx >= 2;
50 }
51
52 CUDA INLINE const U& current() const {
53 assert(current_idx != -1 && current_idx < 2);
54 return children[current_idx];
55 }
56};
57
58}
59
60#endif
Definition bab.hpp:13
Definition light_branch.hpp:11
CUDA INLINE const U & current() const
Definition light_branch.hpp:52
CUDA INLINE const U & next()
Definition light_branch.hpp:31
int current_idx
Definition light_branch.hpp:19
CUDA INLINE void prune()
Definition light_branch.hpp:44
CUDA INLINE LightBranch()
Definition light_branch.hpp:21
U children[2]
Definition light_branch.hpp:16
CUDA INLINE const U & operator[](int idx)
Definition light_branch.hpp:36
LightBranch(const LightBranch &)=default
CUDA INLINE LightBranch(AVar var, const U &left, const U &right)
Definition light_branch.hpp:24
LightBranch(LightBranch &&)=default
CUDA INLINE bool has_next() const
Definition light_branch.hpp:40
int ropes[2]
Definition light_branch.hpp:18
CUDA INLINE bool is_pruned() const
Definition light_branch.hpp:48
AVar var
Definition light_branch.hpp:15