60#define USE_SIMPLE_LIST
62#ifndef USE_SIMPLE_LIST
66#define USE_POOL_ALLOCATOR
89#ifdef USE_POOL_ALLOCATOR
90 #define ONLY_IF_POOL_ALLOCATOR(...) __VA_ARGS__
91 #ifndef USE_SIMPLE_LIST
92 #error "Using the pool allocator also requires using the simple list"
110 template <
class T, std::
size_t BLOCKSIZE = 4000>
112 {
static_assert(std::is_trivially_destructible<T>::value);
113 private:
static_assert(
sizeof(
void*) <=
sizeof(T));
137 return *
static_cast<void**
>(addr);
159 while(
nullptr != block);
166 template <
class U,
class... Args>
168 {
static_assert(
sizeof(T) ==
sizeof(U));
190 return new(new_el) U(std::forward<Args>(args)...);
196 template <
class U,
class... Args>
198 {
static_assert(
sizeof(U) !=
sizeof(T));
208 if constexpr (
sizeof(T) * 2 <
sizeof(U))
221 else if constexpr (
sizeof(T) <
sizeof(U))
239 return new(new_el) U(std::forward<Args>(args)...);
243 template <
class U,
class... Args>
245 {
static_assert(std::is_trivially_destructible<U>::value);
246 if constexpr (
sizeof(U) ==
sizeof(T))
248 return construct_samesize<U>(std::forward<Args>(args)...);
252 return construct_othersize<U>(std::forward<Args>(args)...);
265 {
static_assert(
sizeof(T) ==
sizeof(U));
266 old_el->~U();
static_assert(std::is_trivially_destructible<U>::value);
269 static std::less<const void*>
const total_order;
271 assert(
nullptr != block),
272 total_order(old_el, block->data) ||
273 total_order(&block->data[
sizeof(block->data)], old_el + 1);
274 block = block->next_block )
282 #define ONLY_IF_POOL_ALLOCATOR(...)
285#ifdef USE_SIMPLE_LIST
300 #ifndef USE_POOL_ALLOCATOR
317 template <
class... Args>
321 data(
std::forward<Args>(args)...)
330 #ifdef USE_POOL_ALLOCATOR
361 { assert(
nullptr !=
ptr);
366 { assert(
nullptr !=
ptr);
371 { assert(
nullptr !=
ptr);
375 { assert(
nullptr !=
ptr);
397 using const_iterator::operator==;
398 using const_iterator::operator!=;
437 using iterator::operator*;
438 using iterator::operator->;
439 using iterator::operator==;
440 using iterator::operator!=;
454 { assert(
nullptr != other);
473 {
static_assert(std::is_trivially_destructible<entry>::value);
476 #ifndef USE_POOL_ALLOCATOR
480 for (iterator iter =
begin();
end() != iter; )
482 iterator
next = std::next(iter);
556 template<
class... Args>
558 { assert(
end()==pos || !
empty()); assert(
end()==pos ||
nullptr==pos.ptr->prev);
567 entry*
const new_entry(
569 get_pool().
template construct<entry>
573 (pos.ptr,
prev, std::forward<Args>(args)...));
581 else if (
nullptr !=
prev)
585 prev->next = new_entry;
589 pos.ptr->prev = new_entry;
592 { assert(
nullptr !=
first);
596 assert((
end() == pos ?
before_end() : pos.ptr->prev) == new_entry);
604 template <
class... Args>
607 return emplace(
end(), std::forward<Args>(args)...);
613 template<
class... Args>
615 { assert(
end()==pos || !
empty()); assert(
end()==pos ||
end()!=pos.ptr->prev);
623 entry*
const new_entry(
625 get_pool().
template construct<entry>
629 (
next, pos.ptr, std::forward<Args>(args)...));
640 pos.ptr->next = new_entry;
641 } assert(
nullptr !=
first);
648 next->prev = new_entry;
651 assert((
end() == pos ?
first : pos.ptr->next) == new_entry);
659 template<
class... Args>
672 { assert(from_pos != to_pos);
675 if (
end() != to_pos) {
679 assert(
end() != from_pos); assert(
nullptr != from_pos.
ptr->
prev);
682 assert(from_list.
end() != i);
685 if (from_pos.
ptr != from_list.
first)
686 { assert(
nullptr != from_list.
first->
next);
689 if (
nullptr != from_pos.
ptr->
next)
696 assert(from_pos == from_list.
first->
prev);
704 if (!from_list.
empty())
731 } assert(
nullptr !=
first);
744 if (
end() != to_pos) {
759 { assert(from_pos != to_pos); assert(
end() == to_pos || !
empty());
761 assert(
end() == to_pos ||
nullptr != to_pos.
ptr->
prev);
763 if (
end() != to_pos) {
766 assert(from_list.
end() != from_pos); assert(
nullptr != from_pos.
ptr->
prev);
769 assert(from_list.
end() != i);
772 if (from_pos != from_list.
first)
773 { assert(
nullptr != from_list.
first->
next);
776 if (
nullptr != from_pos.
ptr->
next)
791 if (!from_list.
empty())
833 if (
end() != to_pos) {
842 { assert(
end() != pos); assert(
nullptr != pos.ptr->prev); assert(!
empty());
849 assert(pos.ptr == pos.ptr->prev->next);
850 pos.ptr->prev->next = pos.ptr->next;
851 if (
nullptr != pos.ptr->next)
853 assert(pos.ptr == pos.ptr->next->prev);
854 pos.ptr->next->prev = pos.ptr->prev;
864 assert(
nullptr == pos.ptr->prev->next);
865 first = pos.ptr->next;
868 assert(pos.ptr == pos.ptr->next->prev);
869 pos.ptr->next->prev = pos.ptr->prev;
872 #ifdef USE_POOL_ALLOCATOR
890 { assert(
end() != pos);
908 { assert(
end() != pos);
920 { assert(pos!=
end());
932 { assert(
end() != pos);
946 if (
cend() == other_it || *it != *other_it)
953 return end()==other_it;
966 #define simple_list std::list
972 typedef std::list<El>::iterator iterator;
973 typedef std::list<El>::const_iterator const_iterator;
981 if constexpr (!std::is_trivially_destructible<iterator>::value)
1000 new (&iter) iterator(other); assert(
nullptr != null);
1005 bool is_null()
const {
return nullptr == null; }
1012 if constexpr (!std::is_trivially_destructible<iterator>::value)
1014 if (!is_null()) iter.~iterator();
1019 { assert(
nullptr != null);
1020 return iter.operator->();
1023 { assert(
nullptr != null);
1024 return iter.operator*();
1027 void operator=(nullptr_t)
1029 if constexpr (!std::is_trivially_destructible<iterator>::value)
1031 if (!is_null()) iter.~iterator();
1037 explicit operator iterator()
const
1038 { assert(
nullptr != null);
1043 void operator=(
const iterator& other)
1045 if constexpr (!std::is_trivially_destructible<iterator>::value)
1047 if (!is_null()) iter.~iterator();
1049 new (&iter) iterator(other); assert(
nullptr != null);
1057 if constexpr (
sizeof(null) ==
sizeof(iter))
1059 return &*iter == &*other.iter;
1063 return (is_null() && other.is_null()) ||
1064 (!is_null() && !other.is_null() && &*iter == &*other.iter);
1079 bool operator==(
const const_iterator other)
const
1081 return (
sizeof(null) ==
sizeof(iter) || !is_null()) &&
1086 bool operator!=(
const const_iterator other)
const
1096 { assert(
nullptr != other);
1097 return !is_null() && &*iter == other;
pool_block_t(pool_block_t *const new_next_block)
char data[BLOCKSIZE - sizeof(pool_block_t *)]
pool_block_t * next_block
U * construct(Args &&... args)
allocate and construct a new element (of any type)
static void *& deref_void(void *addr)
U * construct_samesize(Args &&... args)
allocate and construct a new element of the same size as the free list
void * first_free_T
first freed element
U * construct_othersize(Args &&... args)
allocate and construct a new element of a size that doesn't fit the free list
pool_block_t * first_block
first chunk in list of chunks
void destroy(U *const old_el)
destroy and delete some element
void * begin_used_in_first_block
start of part in the first chunk that is already in use
constant iterator class for simple_list
std::forward_iterator_tag iterator_category
const_iterator & operator=(const const_iterator &other)=default
const T & operator*() const
bool operator!=(const const_iterator &other) const
const_iterator & operator++()
const_iterator & operator--()
std::ptrdiff_t difference_type
bool operator==(const const_iterator &other) const
const_iterator(const entry *const new_ptr)
const T * operator->() const
const_iterator(const const_iterator &other)=default
entry(entry *const new_next, entry *const new_prev, Args &&... args)
class that stores either an iterator or a null value
void operator=(std::nullptr_t)
iterator_or_null(std::nullptr_t)
bool operator==(const T *const other) const
bool operator!=(const T *const other) const
iterator_or_null(const iterator &other)
iterator class for simple_list
iterator(const iterator &other)=default
std::forward_iterator_tag iterator_category
iterator(entry *const new_ptr)
std::ptrdiff_t difference_type
iterator & operator=(const iterator &other)=default
a simple implementation of lists
bool empty() const
return true iff the list is empty
const_iterator before_end() const
iterator before_end()
return an iterator to the last element of the list
iterator prev(iterator pos) const
const_iterator cbegin() const
return a constant iterator to the first element of the list
static iterator end()
return an iterator past the last element of the list
iterator emplace_after(iterator pos, Args &&... args)
construct a new list entry after pos
const_iterator prev(const_iterator pos) const
entry * first
pointer to the beginning of the list
const_iterator next(const_iterator pos) const
const_iterator begin() const
return a constant iterator to the first element of the list
iterator emplace_front(Args &&... args)
construct a new list entry at the beginning
void splice_to_after(iterator const to_pos, simple_list< T > &from_list, iterator const from_pos)
iterator next(iterator pos) const
bool operator==(const simple_list &other) const
void splice(iterator const to_pos, simple_list< T > &from_list, iterator const from_pos)
move a list entry from one position to another (possibly in a different list) The function moves the ...
static my_pool< entry > & get_pool()
T & back()
return a reference to the last element of the list
bool check_linked_list() const
T & front()
return a reference to the first element of the list
iterator begin()
return an iterator to the first element of the list
void erase(iterator const pos)
erase an element from a list
bool operator!=(const simple_list &other) const
iterator emplace(iterator pos, Args &&... args)
construct a new list entry before pos
static const_iterator cend()
return a constant iterator past the last element of the list
iterator emplace_back(Args &&... args)
Puts a new element at the end.
bool operator!=(const cs_game_node &n0, const cs_game_node &n1)
typename simple_list< El >::iterator_or_null iterator_or_null_t
bool operator==(const cs_game_node &n0, const cs_game_node &n1)
std::string ptr(const transition t)
Sorts the transitions on labels. Action with the tau label are put first.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
#define USE_POOL_ALLOCATOR