20 #define AGX_USE_AGX_LIST_IMPL 1 22 #if AGX_USE_AGX_LIST_IMPL 33 #define AGX_LIST_ITERATOR_TYPEDEFS \ 34 typedef std::bidirectional_iterator_tag iterator_category; \ 35 typedef T& reference; \ 36 typedef const T& const_reference; \ 38 typedef const T* const_pointer; \ 39 typedef T value_type; \ 40 typedef ptrdiff_t difference_type 42 template <
typename T >
61 template<
typename T >
70 template<
typename T >
78 explicit ItOp( value_type num )
81 template<
typename ItT,
typename Op >
85 for ( value_type i = value_type( 0 ); i < m_num; ++i )
94 template<
typename ItT >
100 template<
typename ItT >
106 template <
typename T >
143 m_ptr = m_ptr->m_next;
158 m_ptr = m_ptr->m_prev;
173 return m_ptr->m_element;
177 return &(m_ptr->m_element);
181 return m_ptr == i.m_ptr;
185 return m_ptr != i.m_ptr;
200 inline explicit iterator( node_ptr_type ptr ) : m_ptr( ptr ) {}
212 m_ptr = m_ptr->m_next;
227 m_ptr = m_ptr->m_prev;
242 return m_ptr->m_element;
246 return &(m_ptr->m_element);
250 return m_ptr == i.m_ptr;
254 return m_ptr == i.m_ptr;
258 return m_ptr != i.m_ptr;
262 return m_ptr != i.m_ptr;
311 m_ptr = m_ptr->m_prev;
326 m_ptr = m_ptr->m_next;
341 return m_ptr->m_prev->m_element;
345 return &(m_ptr->m_prev->m_element);
349 return m_ptr == i.m_ptr;
353 return m_ptr != i.m_ptr;
387 m_ptr = m_ptr->m_prev;
402 m_ptr = m_ptr->m_next;
417 return m_ptr->m_prev->m_element;
421 return &(m_ptr->m_prev->m_element);
425 return m_ptr == i.m_ptr;
429 return m_ptr != i.m_ptr;
443 bool operator()( const_reference obj )
const {
return m_obj == obj; }
454 bool operator()( const_reference left, const_reference right )
const {
return left == right; }
461 bool operator()( const_reference obj )
const {
return m_obj == obj; }
472 bool operator()( const_reference left, const_reference right )
const {
return left < right; }
480 :
m_size( 0 ), m_end( allocate() ), m_front( m_end )
488 :
m_size( 0 ), m_end( allocate() ), m_front( m_end )
499 if ( m_front == m_end && m_front !=
nullptr )
500 deallocate( m_front );
511 if (
this == &other )
526 if ( size() != other.
size() )
529 for ( const_iterator myIt =
begin(), otherIt = other.
begin(), endIt =
end(); myIt != endIt; ++myIt, ++otherIt )
530 if ( *myIt != *otherIt )
541 const_iterator
find( const_reference _val )
const 544 iterator iend(m_end);
545 for ( ; i != iend; ++i ) {
546 if ( *i == _val )
return i;
556 iterator
find( const_reference _val )
559 iterator iend(m_end);
560 for ( ; i != iend; ++i ) {
561 if ( *i == _val )
return i;
573 return find( _val ) !=
end();
579 inline iterator
begin() {
return iterator( m_front ); }
584 inline const_iterator
begin()
const {
return const_iterator( m_front ); }
589 inline iterator
end() {
return iterator( m_end ); }
594 inline const_iterator
end()
const {
return const_iterator( m_end ); }
599 inline reverse_iterator
rbegin() {
return reverse_iterator( m_end ); }
604 inline const_reverse_iterator
rbegin()
const {
return const_reverse_iterator( m_end ); }
609 inline reverse_iterator
rend() {
return reverse_iterator( m_front ); }
614 inline const_reverse_iterator
rend()
const {
return const_reverse_iterator( m_front ); }
636 inline const_reference
front()
const {
agxAssert( !empty() );
return m_front->m_element; }
642 inline reference
back() {
agxAssert( !empty() );
return m_end->m_prev->m_element; }
648 inline const_reference
back()
const {
agxAssert( !empty() );
return m_end->m_prev->m_element; }
656 inline iterator
insert( const_iterator _where, const_reference c_ref )
658 node_ptr_type node = allocate();
661 node->
m_next = _where.m_ptr;
662 _where.m_ptr->
m_prev = node;
664 if ( node->
m_prev ==
nullptr ) {
670 return iterator(node);
679 template<
typename InputIterator >
680 void insert( const_iterator _where, InputIterator _first, InputIterator _last )
682 for ( ; _first != _last; ++_first ) {
683 insert( _where, *_first );
693 insert(
end(), c_ref );
702 insert(
begin(), c_ref );
740 inline iterator
erase( const_iterator _where )
742 if ( _where.m_ptr == m_front ) {
743 m_front = m_front->m_next;
744 m_front->m_prev =
nullptr;
746 deallocate( _where.m_ptr );
752 return iterator(m_front);
755 _where.m_ptr->m_prev->m_next = _where.m_ptr->m_next;
756 _where.m_ptr->m_next->m_prev = _where.m_ptr->m_prev;
758 node_ptr_type ret = _where.m_ptr->m_prev;
760 deallocate( _where.m_ptr );
765 return iterator(ret);
773 template<
typename Pred >
776 node_ptr_type node = m_front;
778 while ( node != m_end ) {
780 node = erase( const_iterator( node ) ).m_ptr;
790 inline void remove( const_reference valArg )
792 remove_if( EqualPred1( valArg ) );
801 template<
typename Pred >
802 void merge( my_type& other, Pred pred )
804 if (
this != &other ) {
805 iterator myIt =
begin();
806 iterator myEnd =
end();
808 const_iterator otherIt = other.
begin();
809 const_iterator otherEnd = other.
end();
811 while ( myIt != myEnd && otherIt != otherEnd ) {
812 if ( pred( *otherIt, *myIt ) ) {
813 const_iterator otherNext = otherIt;
814 splice( myIt, other, otherIt, ++otherNext, 1 );
820 if ( otherIt != otherEnd )
821 splice( myEnd, other, otherIt, otherEnd, other.m_size );
834 merge( other, LessPred2() );
841 template<
typename Pred >
847 const const_iterator endIt =
end();
848 iterator curr =
begin();
849 iterator prev = curr++;
850 while ( curr != endIt ) {
853 if ( pred( *prev, *curr ) )
854 curr = ++erase( curr );
866 unique( EqualPred2() );
877 node_ptr_type node = m_front;
879 const node_ptr_type next = node->
m_next;
882 if ( node == m_end ) {
883 node_ptr_type tmp = m_front;
885 m_front->
m_prev =
nullptr;
899 std::swap( m_front, other.m_front );
900 std::swap( m_end, other.m_end );
901 std::swap(
m_size, other.m_size );
907 template<
typename Pred >
913 const size_type MAXBINS = 25;
915 my_type binList[ MAXBINS + 1 ];
917 size_type maxBin = 0;
922 for ( ; bin < maxBin && !binList[ bin ].
empty(); ++bin ) {
923 binList[ bin ].
merge( tmpList, pred );
924 binList[ bin ].
swap( tmpList );
927 if ( bin == MAXBINS )
928 binList[ bin - 1 ].
merge( tmpList, pred );
930 binList[ bin ].
swap( tmpList );
931 maxBin += size_type( bin == maxBin );
935 for ( size_type bin = 1; bin < maxBin; ++bin )
936 binList[ bin ].merge( binList[ bin - 1 ], pred );
938 splice(
end(), binList[ maxBin - 1 ], binList[ maxBin - 1 ].
begin(), binList[ maxBin - 1 ].
end(), binList[ maxBin - 1 ].size() );
949 void splice( const_iterator _where, my_type& other, const_iterator first, const_iterator last, size_type count )
954 if (
this != &other ) {
956 other.m_size -= count;
960 if ( first.m_ptr->m_prev ==
nullptr )
961 other.m_front = last.m_ptr;
967 if ( _where.m_ptr->m_prev ==
nullptr )
968 m_front = first.m_ptr;
972 node_ptr_type node = _where.m_ptr->
m_prev;
975 first.m_ptr->
m_prev = node;
983 void splice( const_iterator _where, my_type& other )
985 splice( _where, other, other.
begin(), other.
end(), other.
size() );
996 void splice( const_iterator _where, my_type& other, const_iterator first, const_iterator last )
999 if ( first == other.
begin() && last == other.
end() )
1000 count = other.
size();
1001 else for ( const_iterator i = first; i != last; ++i, ++count )
1003 splice( _where, other, first, last, count );
1011 sort( LessPred2() );
1015 node_ptr_type allocate()
1017 return new node_type();
1020 void deallocate( node_ptr_type node )
1027 node_ptr_type m_end;
1028 node_ptr_type m_front;
1039 template<
typename T >
1040 class List :
public std::list< T > {};
AGX_LIST_ITERATOR_TYPEDEFS
iterator(const iterator &rhs)
const_pointer operator->() const
void sort(Pred pred)
Sorts the content in this list given pred.
AGX_LIST_ITERATOR_TYPEDEFS
AGXTERRAIN_EXPORT void clear()
LNode< T > & node_ref_type
const_reverse_iterator(const const_iterator &rhs)
AGX_LIST_ITERATOR_TYPEDEFS
T & operator()(T &val) const
reverse_iterator(const iterator &rhs)
reverse_iterator operator+(const agx::ItOp &inc) const
List(const List &other)
Copy constructor.
bool operator()(const_reference left, const_reference right) const
reverse_iterator(node_ptr_type ptr)
bool operator!=(const const_reverse_iterator &i) const
void swap(my_type &other)
Swap this with other.
void remove_if(Pred pred)
Erase (all) elements matching pred.
LNode< T > * node_ptr_type
reverse_iterator & operator=(const const_reverse_iterator &rhs)
pointer operator->() const
const_iterator & operator=(const const_iterator &rhs)
bool operator==(const my_type &other) const
Comparison of lists of same size.
void pop_back()
Remove last element in this list.
reference operator*() const
reference operator*() const
void push_front(const_reference c_ref)
Add element to the front of this list.
pointer operator->() const
void sort()
Sorts the content in this list given operator<.
T & operator()(T &val) const
EqualPred1(const_reference obj)
iterator operator+(const agx::ItOp &inc) const
void merge(my_type &other, Pred pred)
Merge in elements from other, both this and other are ordered by pred.
const_reference front() const
reverse_iterator & operator++()
iterator operator-(const agx::ItOp &inc) const
const_iterator(node_ptr_type ptr)
reverse_iterator rbegin()
const_reverse_iterator(const const_reverse_iterator &rhs)
const_iterator operator++(int)
void pop_front()
Remove first element in this list.
AgXString< T > operator+(const Indentation &indentation, const AgXString< T > &str)
const_reverse_iterator operator+(const agx::ItOp &inc) const
iterator insert(const_iterator _where, const_reference c_ref)
Insert an element c_ref before _where.
const_reverse_iterator & operator=(const const_iterator &rhs)
void merge(my_type &other)
Merge in elements from other, both this and other are ordered by operator<.
const_reverse_iterator operator--(int)
bool operator==(const const_reverse_iterator &i) const
iterator(node_ptr_type ptr)
const_iterator & operator--()
void insert(const_iterator _where, InputIterator _first, InputIterator _last)
Insert N elements before _where.
bool operator()(const_reference left, const_reference right) const
const T & const_reference
List()
Default constructor, size zero and begin() == end().
const_iterator operator-(const agx::ItOp &inc) const
reverse_iterator operator--(int)
bool contains(const_reference _val)
Check if a value _val is part of this list (at least one time).
void clear()
Clear this list of all elements.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
ItT operator-(const ItT &it, const agx::ItOp &inc)
const_reverse_iterator & operator++()
reverse_iterator & operator=(const iterator &rhs)
const_reverse_iterator(node_ptr_type ptr)
bool operator!=(const reverse_iterator &i) const
const_iterator operator--(int)
const_reverse_iterator rend() const
bool operator!=(const const_iterator &i) const
const_reverse_iterator & operator=(const iterator &rhs)
void splice(const_iterator _where, my_type &other)
Splice other [other.begin(), other.end()) at _where.
bool operator!=(const iterator &i) const
bool operator==(const iterator &i) const
bool operator==(const const_iterator &i) const
ItT operator()(const ItT &org, Op op) const
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
iterator find(const_reference _val)
Find iterator to FIRST element with value _val.
const_reverse_iterator & operator=(const const_reverse_iterator &rhs)
const_reverse_iterator rbegin() const
reverse_iterator operator-(const agx::ItOp &inc) const
reverse_iterator(const reverse_iterator &rhs)
const_reverse_iterator operator-(const agx::ItOp &inc) const
reverse_iterator operator++(int)
bool operator()(const_reference obj) const
List & operator=(const my_type &other)
Assignment operator.
const_iterator & operator++()
reverse_iterator & operator--()
iterator & operator=(const iterator &rhs)
bool operator==(const reverse_iterator &i) const
const_reverse_iterator(const iterator &rhs)
void reverse()
Reverse sequence.
iterator erase(const_iterator _where)
Erase element at _where.
const_iterator(const const_iterator &rhs)
LessPred1(const_reference obj)
const_reverse_iterator & operator--()
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
void splice(const_iterator _where, my_type &other, const_iterator first, const_iterator last)
Splice other [first, last) at _where.
AGX_LIST_ITERATOR_TYPEDEFS
const_iterator begin() const
const_reverse_iterator operator++(int)
const_iterator operator+(const agx::ItOp &inc) const
const_iterator end() const
void splice(const_iterator _where, my_type &other, const_iterator first, const_iterator last, size_type count)
Splice other [first, last) at _where.
const_reference back() const
void unique(Pred pred)
Erases each element satisfying pred with previous.
void unique()
Erases each element satisfying operator== with previous.
bool operator==(const const_iterator &i) const
const_iterator find(const_reference _val) const
Find iterator to FIRST element with value _val.
const_pointer operator->() const
const_reference operator*() const
void push_back(const_reference c_ref)
Add element to the back of this list.
bool operator!=(const const_iterator &i) const
const_reference operator*() const
bool operator()(const_reference obj) const