16 CLANG_WARNING_DISABLE(
"-Wnull-pointer-arithmetic")
41 template<
class Entry,
bool FastIndex>
50 delete[] (_array + 1);
53 Entry& operator []( Node n );
54 const Entry& operator []( Node n )
const;
58 return _lastLeaf ==
Node( 0 );
63 return _lastLeaf.getNormalIndex();
68 return _capacityEnd.getNormalIndex();
95 Node leftSibling()
const;
96 Node next(
size_t count = 1)
const;
107 return *
this ==
Node();
112 return fi ? !(_index & S) : !(_index & 1);
117 return fi ? _index & S : _index & 1;
122 return _index < node.
_index;
127 return _index <= node.
_index;
132 return _index > node.
_index;
137 return _index >= node.
_index;
142 return _index == node.
_index;
147 return _index != node.
_index;
152 static const bool fi = FastIndex;
153 static const size_t S =
sizeof(Entry);
160 return fi ? _index / S : _index;
166 void print( std::ostream& out )
const;
177 std::vector<Entry> ret;
178 while( it <= _lastLeaf )
180 ret.push_back( (*
this)[it] );
193 template<
class E,
bool FI>
196 _lastLeaf =
Node( 0 );
199 template<
class E,
bool FI>
202 return capacity() *
sizeof(E);
205 template<
class E,
bool FI>
212 template<
class E,
bool FI>
213 CompactTree<E, FI>::CompactTree(
size_t initialCapacity ):
214 _array( static_cast<E*>(nullptr) - 1 ),
216 _capacityEnd( Node( 0 ).next( initialCapacity ))
218 if( initialCapacity > 0 ) {
219 _array =
new E[initialCapacity]-1;
224 template<
class E,
bool FI>
225 CompactTree<E, FI>::CompactTree(
const CompactTree& tree,
size_t minCapacity ):
226 _array( static_cast<E*>(0) - 1 ),
227 _lastLeaf( tree._lastLeaf )
229 if( tree.size() > minCapacity ) {
230 minCapacity = tree.size();
232 _capacityEnd = Node( 0 ).next( minCapacity );
233 if( minCapacity == 0 ) {
236 _array =
new E[minCapacity]-1;
237 for( Node i; i <= tree.lastLeaf(); ++i ) {
238 (*this)[i] = tree[i];
242 template<
class E,
bool FI>
248 char* base =
reinterpret_cast<char*
>(_array);
249 E* element =
reinterpret_cast<E*
>(base + n.
_index);
250 assert( element == &(_array[n.
_index /
sizeof(E)]) );
254 template<
class E,
bool FI>
260 template<
class E,
bool FI>
263 if( _lastLeaf == _capacityEnd ) {
266 _lastLeaf = _lastLeaf.next();
267 (*this)[lastLeaf()] = value;
270 template<
class E,
bool FI>
273 assert( _lastLeaf != _capacityEnd );
274 _lastLeaf = _lastLeaf.next();
275 (*this)[lastLeaf()] = value;
278 template<
class E,
bool FI>
281 assert( _lastLeaf >=
Node() );
282 _lastLeaf = _lastLeaf.prev();
285 template<
class E,
bool FI>
293 template<
class E,
bool FI>
296 return fi ?
Node( (_index / (2 * S)) * S ) :
Node( _index / 2 );
299 template<
class E,
bool FI>
302 return Node( 2 * _index );
305 template<
class E,
bool FI>
308 return fi ?
Node( 2 * _index + S ) :
Node( 2 * _index + 1 );
311 template<
class E,
bool FI>
314 return fi ?
Node( _index ^ S ) :
Node( _index ^ 1 );
317 template<
class E,
bool FI>
320 return fi ?
Node( _index & ~S ) :
Node( _index & ~1 );
324 template<
class E,
bool FI>
327 return fi ?
Node( _index + S * count ) :
Node( _index + count );
330 template<
class E,
bool FI>
333 return fi ?
Node( _index - S ) :
Node( _index - 1 );
336 template<
class E,
bool FI>
339 Node last = lastLeaf();
340 for(
Node i; i <= last; i = i.
next() )
342 if( (i._index & (i._index - 1)) == 0 ) {
343 out <<
"\n " << i._index <<
':';
345 out <<
' ' << (*this)[i] <<
" := ";
347 (*this)[i]->print( out );
352 template<
class E,
bool FI>
356 assert( !FI || (
sizeof(E) & (
sizeof(E) - 1)) == 0 );
357 if( capacity() == 0 )
359 assert( _array ==
static_cast<E*
>(
nullptr) - 1 );
360 assert( _capacityEnd ==
Node( 0 ));
361 assert( _lastLeaf ==
Node( 0 ));
365 assert( _array !=
static_cast<E*
>(
nullptr) - 1 );
366 assert( _capacityEnd >
Node( 0 ));
367 assert( _lastLeaf <= _capacityEnd );
372 template<
class E,
bool FI>
375 return Node( _capacityEnd._index - _lastLeaf._index ) >=
Node( 0 ).
next( extraCapacity );
378 template<
class E,
bool FI>
382 for(
Node i; i <= lastLeaf(); i = i.next() ) {
std::ostream & operator<<(std::ostream &os, const GbBenchmark< C, O, P > &b)
carl is the main namespace for the library.
bool operator>(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
void swap(Variable &lhs, Variable &rhs)
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator!=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator<=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator>=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::enable_if<!reverse, I >::type & operator++(BaseIterator< T, I, reverse > &it)
void print(CaseDistinction< Poly > &_substitutionResults)
Prints the given disjunction of conjunction of constraints.
This class represents a tree.
This class packs a complete binary tree in a vector.
void print(std::ostream &out) const
void pushBackWithCapacity(const Entry &value)
bool hasFreeCapacity(size_t extraCapacity) const
void swap(CompactTree &tree)
std::vector< Entry > getCopy() const
CompactTree(std::size_t initialCapacity=0)
std::size_t getMemoryUse() const
CompactTree(const CompactTree &tree, std::size_t minCapacity=0)
std::size_t capacity() const
void pushBack(const Entry &value)
size_t getNormalIndex() const
Node next(size_t count=1) const