Lattice Land Powerdomains Library
Loading...
Searching...
No Matches
branch.hpp
Go to the documentation of this file.
1// Copyright 2022 Pierre Talbot
2
3#ifndef LALA_POWER_BRANCH_HPP
4#define LALA_POWER_BRANCH_HPP
5
6#include "battery/vector.hpp"
7#include "lala/logic/logic.hpp"
8
9namespace lala {
10
11template <class TellTy, class Alloc>
12class Branch {
13public:
14 using tell_type = TellTy;
15 using allocator_type = Alloc;
16
17 template <class TellTy2, class Alloc2>
18 friend class Branch;
19
20private:
21 battery::vector<tell_type, allocator_type> children;
22 int current_idx;
23
24public:
25 CUDA Branch(const allocator_type& alloc = allocator_type()): children(alloc), current_idx(-1) {}
26 Branch(const Branch&) = default;
27 Branch(Branch&&) = default;
28 CUDA Branch(battery::vector<tell_type, allocator_type>&& children)
29 : children(std::move(children)), current_idx(-1) {}
30
31 template <class BranchType>
32 CUDA Branch(const BranchType& branch, const allocator_type& alloc = allocator_type())
33 : children(branch.children, alloc), current_idx(branch.current_idx) {}
34
35 CUDA int size() const {
36 return static_cast<int>(children.size()/*size_t*/);
37 }
38
39 CUDA const tell_type& next() {
40 assert(has_next());
41 return children[++current_idx];
42 }
43
44 CUDA const tell_type& operator[](size_t idx) {
45 return children[idx];
46 }
47
48 CUDA bool has_next() const {
49 return current_idx + 1 < size();
50 }
51
52 CUDA void prune() {
53 current_idx = size();
54 }
55
56 CUDA bool is_pruned() const {
57 return current_idx >= size();
58 }
59
60 CUDA const tell_type& current() const {
61 assert(current_idx != -1 && current_idx < children.size());
62 return children[current_idx];
63 }
64};
65
66}
67
68#endif
Definition branch.hpp:12
CUDA int size() const
Definition branch.hpp:35
CUDA const tell_type & operator[](size_t idx)
Definition branch.hpp:44
CUDA Branch(const BranchType &branch, const allocator_type &alloc=allocator_type())
Definition branch.hpp:32
CUDA const tell_type & current() const
Definition branch.hpp:60
TellTy tell_type
Definition branch.hpp:14
CUDA void prune()
Definition branch.hpp:52
CUDA bool is_pruned() const
Definition branch.hpp:56
Alloc allocator_type
Definition branch.hpp:15
CUDA Branch(battery::vector< tell_type, allocator_type > &&children)
Definition branch.hpp:28
Branch(Branch &&)=default
CUDA bool has_next() const
Definition branch.hpp:48
Branch(const Branch &)=default
CUDA const tell_type & next()
Definition branch.hpp:39
CUDA Branch(const allocator_type &alloc=allocator_type())
Definition branch.hpp:25
Definition bab.hpp:13