Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DynamicSet.h
Go to the documentation of this file.
1 
13 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_DYNAMIC_SET_H
14 #define INCLUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_DYNAMIC_SET_H
15 
17 
18 namespace Scine {
19 namespace Molassembler {
20 namespace Temple {
21 
29 template<
30  typename T,
31  size_t nItems,
32  class LessThanPredicate = std::less<T>,
33  class EqualityPredicate = std::equal_to<T>
34 > class DynamicSet {
35 private:
37 
38  TreeType tree_;
39 
40 public:
42  constexpr DynamicSet() = default;
43 
48  template<
49  template<typename, size_t> class ArrayType,
50  size_t size
51  > constexpr DynamicSet(const ArrayType<T, size>& items) {
52  for(const auto& item : items) {
53  tree_.insert(item);
54  }
55  }
56 
61  PURITY_WEAK constexpr bool contains(const T& item) const {
62  return tree_.contains(item);
63  }
64 
69  constexpr void insert(const T& item) {
70  tree_.insert(item);
71  }
72 
73  PURITY_WEAK constexpr Optional<const T&> getOption(const T& item) const {
74  return tree_.getOption(item);
75  }
76 
78  constexpr void clear() {
79  tree_.clear();
80  }
81 
82  using const_iterator = typename TreeType::const_iterator;
83 
84  PURITY_WEAK constexpr const_iterator begin() const {
85  return tree_.begin();
86  }
87 
88  PURITY_WEAK constexpr const_iterator end() const {
89  return tree_.end();
90  }
91 
92  PURITY_WEAK constexpr size_t size() const {
93  return tree_.size();
94  }
95 
96  PURITY_WEAK constexpr bool operator == (const DynamicSet& other) const {
97  return tree_ == other.tree_;
98  }
99 
100  PURITY_WEAK constexpr bool operator != (const DynamicSet& other) const {
101  return !(
102  tree_ == other.tree_
103  );
104  }
105 
106  PURITY_WEAK constexpr bool operator < (const DynamicSet& other) const {
107  return tree_ < other.tree_;
108  }
109 
110  PURITY_WEAK constexpr bool operator > (const DynamicSet& other) const {
111  return other.tree_ < tree_;
112  }
113 };
114 
116 template<
117  size_t nItems,
118  typename T,
119  template<typename, size_t> class ArrayType,
120  class LessThanPredicate = std::less<T>,
121  class EqualityPredicate = std::equal_to<T>
123  const ArrayType<T, nItems>& array
124 ) {
126 }
127 
128 } // namespace Temple
129 } // namespace Molassembler
130 } // namespace Scine
131 
132 #endif
PURITY_WEAK constexpr bool contains(const T &item) const
Check if the set contains an element.
Definition: DynamicSet.h:61
#define PURITY_WEAK
Definition: Preprocessor.h:36
An Option monadic type.
Definition: Optional.h:33
constexpr DynamicSet(const ArrayType< T, size > &items)
Constructor from existing ordered data.
Definition: DynamicSet.h:51
constexpr BTree
PURITY_WEAK constexpr const_iterator end() const
Returns a past-the-end const iterator.
Definition: BTree.h:615
PURITY_WEAK constexpr Optional< const T & > getOption(const T &value) const
Checks if the tree contains T. If so, returns a const-ref to it.
Definition: BTree.h:245
PURITY_WEAK constexpr unsigned size() const
Returns the number of elements in the tree.
Definition: BTree.h:340
constexpr DynamicSet< T, nItems, LessThanPredicate > makeDynamicSet(const ArrayType< T, nItems > &array)
Helper function to create a DynamicSet specifying only the maximum size.
Definition: DynamicSet.h:122
constexpr void insert(const T &value)
Add a value to the tree.
Definition: BTree.h:181
constexpr DynamicSet()=default
Dynamic set.
Temple::Array< T, size > ArrayType
Definition: Properties.h:143
PURITY_WEAK constexpr const_iterator begin() const
Returns a const iterator to the first value in the tree.
Definition: BTree.h:607
constexpr void clear()
Remove all elements of the set.
Definition: DynamicSet.h:78
Tree-based set.
Definition: DynamicSet.h:34
constexpr void clear()
Clears the tree.
Definition: BTree.h:160
PURITY_WEAK constexpr bool contains(const T &value) const
Check whether a value exists in the tree.
Definition: BTree.h:231
constexpr void insert(const T &item)
Insertion an element into the set.
Definition: DynamicSet.h:69