15 #ifndef INCG_IRIS_IUTEST_LIST_HPP_CB5AECEA_6147_4A89_BB97_236338CA177E_
16 #define INCG_IRIS_IUTEST_LIST_HPP_CB5AECEA_6147_4A89_BB97_236338CA177E_
20 #if IUTEST_USE_OWN_LIST
32 #if IUTEST_USE_OWN_LIST
43 typedef TN *value_ptr;
44 typedef iu_list_node<TN> _Myt;
59 template<
typename NODE,
typename NODE_PTR,
typename NODE_REF>
60 class iu_list_iterator
62 typedef iu_list_iterator<NODE, NODE_PTR, NODE_REF> _Myt;
64 typedef NODE value_type;
65 typedef NODE_PTR value_ptr;
66 typedef NODE_REF value_ref;
67 typedef value_ptr pointer;
68 typedef value_ref reference;
69 typedef int distance_type;
70 typedef int difference_type;
83 bool operator == (
const _Myt& it)
const {
return this->m_node == it.m_node; }
84 bool operator != (
const _Myt& it)
const {
return this->m_node != it.m_node; }
86 _Myt& operator ++ () { m_node = m_node->next;
return *
this; }
87 _Myt& operator -- () { m_node = m_node->prev;
return *
this; }
92 operator value_ptr () {
return ptr(); }
94 _Myt operator + (
int n)
102 return this->operator +(
static_cast<unsigned int>(n));
106 for(
int i=0; i < n && ret.m_node != NULL; ++i )
108 ret.m_node = ret.m_node->prev;
113 _Myt operator + (
unsigned int n)
116 for(
unsigned int i=0; i < n && ret.m_node != NULL; ++i )
118 ret.m_node = ret.m_node->next;
129 template<
typename NODE>
132 typedef NODE *node_ptr;
133 typedef iu_list<NODE> _Myt;
138 typedef iu_list_iterator<NODE, NODE*, NODE&> iterator;
139 typedef iu_list_iterator<NODE, const NODE*, const NODE&> const_iterator;
148 node_ptr cur = m_node;
162 void sort_insert(node_ptr p)
178 node_ptr next = m_node;
185 node_ptr prev = m_node;
186 node_ptr cur = m_node->next;
206 void push_back(node_ptr p)
219 node_ptr prev = m_node;
220 node_ptr cur = m_node->next;
234 void remove(node_ptr p)
244 if( p->prev == NULL )
254 p->prev->next = p->next;
255 if( p->next != NULL )
257 p->next->prev = p->prev;
260 p->prev = p->next = NULL;
262 void erase(iterator it)
274 for(
unsigned int i=2, n=count(); i<n; ++i )
276 swap(begin() + (i-2), begin() + r(i) % i );
281 void swap(iterator a, iterator b)
287 if( a.ptr() == m_node )
291 else if( b.ptr() == m_node )
296 if( a->next == b.ptr() )
302 if( a->next != NULL )
304 a->next->prev = a.ptr();
306 if( b->prev != NULL )
308 b->prev->next = b.ptr();
311 else if( a->prev == b.ptr() )
317 if( b->next != NULL )
319 b->next->prev = b.ptr();
321 if( a->prev != NULL )
323 a->prev->next = a.ptr();
328 node_ptr tmp = a->next;
334 if( a->next != NULL )
336 a->next->prev = a.ptr();
338 if( b->next != NULL )
340 b->next->prev = b.ptr();
342 if( a->prev != NULL )
344 a->prev->next = a.ptr();
346 if( b->prev != NULL )
348 b->prev->next = b.ptr();
360 return iterator(NULL);
368 return const_iterator(NULL);
376 bool operator () (
const T* lhs,
const T* rhs)
const {
return *lhs == *rhs; }
379 template<
typename FUNC>
380 node_ptr find(node_ptr p, FUNC& f)
const
382 node_ptr cur = m_node;
393 template<
typename FUNC>
394 node_ptr find(FUNC& f)
const
396 node_ptr cur = m_node;
409 node_ptr operator -> () {
return m_node; }
410 node_ptr operator & () {
return m_node; }
411 NODE& operator * () {
return *m_node; }
413 node_ptr operator [] (
int index)
const
415 node_ptr cur = m_node;
416 for(
int i=0; i < index; ++i )
427 bool operator == (node_ptr p)
const {
return m_node == p; }
428 bool operator != (node_ptr p)
const {
return m_node != p; }
439 node_ptr prev = m_node;
440 node_ptr curr = prev->next;
441 while( curr != NULL )
443 assert( prev->next == curr );
444 assert( curr->prev == prev );
456 IUTEST_PRAGMA_WARN_PUSH()
457 IUTEST_PRAGMA_WARN_DISABLE_NOEXCEPT_TPYE()
462 template<typename It>
463 void RandomShuffle(It begin, It last, iuRandom& r)
465 r.shuffle(begin, last);
467 #if IUTEST_USE_OWN_LIST
468 template<
typename Node,
typename Fn>
469 void RandomShuffle(iu_list<Node>& list, Fn& r)
474 template<
typename T,
typename Fn>
475 void RandomShuffle(::std::vector<T>& list, Fn& r)
477 RandomShuffle(list.begin(), list.end(), r);
480 #if IUTEST_USE_OWN_LIST
481 template<
typename Node,
typename Fn>
482 Node* FindList(
const iu_list<Node>& list, Fn& f)
487 template<
typename T,
typename Fn>
488 T FindList(const ::std::vector<T>& list, Fn& f)
490 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
505 #if IUTEST_USE_OWN_LIST
507 template<
typename Node,
typename Fn>
508 int CountIf(
const iu_list<Node>& list, Fn f)
511 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
523 template<
typename T,
typename Fn>
524 int CountIf(const ::std::vector<T>& list, Fn f)
527 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
543 #if IUTEST_USE_OWN_LIST
545 template<
typename Node,
typename Fn>
546 int SumOverList(
const iu_list<Node>& list, Fn f)
549 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
551 count += ((*it)->*f)();
558 template<
typename T,
typename Fn>
559 int SumOverList(const ::std::vector<T>& list, Fn f)
562 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
564 count += ((*it)->*f)();
575 #if IUTEST_USE_OWN_LIST
577 template<
typename Node,
typename Fn>
578 int CountIfOverList(
const iu_list<Node>& list, Fn f)
581 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
593 template<
typename T,
typename Fn>
594 int CountIfOverList(const ::std::vector<T>& list, Fn f)
597 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
612 #if IUTEST_USE_OWN_LIST
614 template<
typename Node,
typename Fn>
615 bool AnyOverList(
const iu_list<Node>& list, Fn f)
617 for(
typename iu_list<Node>::const_iterator it = list.begin(), end=list.end(); it != end; ++it )
629 template<
typename T,
typename Fn>
630 bool AnyOverList(const ::std::vector<T>& list, Fn f)
632 for(typename ::std::vector<T>::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
644 IUTEST_PRAGMA_WARN_POP()
650 #endif // INCG_IRIS_IUTEST_LIST_HPP_CB5AECEA_6147_4A89_BB97_236338CA177E_