libcsdbg  1.28
C++ exception (and generic) stack trace debug library
template<class T >
node< T > * csdbg::chain< T >::node_at ( u32  i) const
protectedvirtual

Get the node at a chain offset.

Parameters
[in]ithe offset
Returns
the i-th node
Exceptions
csdbg::exception

Definition at line 105 of file chain.hpp.

References likely, csdbg::node< T >::link(), and unlikely.

106 {
107  if ( unlikely(i >= m_size) )
108  throw exception("offset out of chain bounds (%d >= %d)", i, m_size);
109 
110  /* Select traversal direction */
111  node<T> *cur = m_head;
112  i32 j = i, mid = m_size / 2;
113  if (j >= mid) {
114  j = m_size - i - 1;
115  cur = m_tail;
116  }
117 
118  node<T> *prev = NULL, *next;
119  while ( likely(j-- > 0) ) {
120  next = cur->link(prev);
121  prev = cur;
122  cur = next;
123  }
124 
125  return cur;
126 }
u32 m_size
Node count.
Definition: chain.hpp:43
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
node< T > * m_tail
Chain tail.
Definition: chain.hpp:41
node< T > * m_head
Chain head.
Definition: chain.hpp:39
int i32
32-bit signed integer
Definition: config.hpp:82
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function: