graph_node_list.h#

Intrusive doubly-linked list used exclusively for Graph node lists.

Provides generic_graph_node_list and generic_graph_node_list_iterator, together with concrete type aliases for mutable and const graph node lists.

Attention

The code in this file is highly EXPERIMENTAL. The APIs will probably change.

namespace ONNX_LIGHT_NAMESPACE

Typedefs

using graph_node_list = generic_graph_node_list<Node>#

Mutable graph node list over Node elements.

using const_graph_node_list = generic_graph_node_list<const Node>#

Read-only graph node list over const Node elements.

using graph_node_list_iterator = generic_graph_node_list_iterator<Node>#

Mutable iterator over a graph_node_list.

using const_graph_node_list_iterator = generic_graph_node_list_iterator<const Node>#

Read-only iterator over a const_graph_node_list.

Functions

template<typename T>
static inline bool operator==(generic_graph_node_list_iterator<T> a, generic_graph_node_list_iterator<T> b)#

Equality comparison for two iterators.

Two iterators compare equal when they point to the same node.

Template Parameters:

T – Element type.

Parameters:
  • a – Left-hand iterator.

  • b – Right-hand iterator.

Returns:

true if both iterators point to the same node.

template<typename T>
static inline bool operator!=(generic_graph_node_list_iterator<T> a, generic_graph_node_list_iterator<T> b)#

Inequality comparison for two iterators.

Template Parameters:

T – Element type.

Parameters:
  • a – Left-hand iterator.

  • b – Right-hand iterator.

Returns:

true if the iterators point to different nodes.

Variables

static constexpr size_t kNextDirection = 0#

Direction index for forward (next-pointer) traversal.

static constexpr size_t kPrevDirection = 1#

Direction index for reverse (previous-pointer) traversal.

template<typename T>
struct generic_graph_node_list#
#include <graph_node_list.h>

Intrusive doubly-linked list view over graph nodes.

Does not own the nodes; it merely provides a range interface around the sentinel head pointer and a traversal direction. Supports both forward (begin/end) and reverse (rbegin/rend) iteration. A reversed view of the same list is obtained via reverse().

Template Parameters:

T – Element type, either Node or const Node.

Public Types

using iterator = generic_graph_node_list_iterator<T>#

Mutable iterator type.

using const_iterator = generic_graph_node_list_iterator<const T>#

Read-only iterator type.

Public Functions

inline generic_graph_node_list_iterator<T> begin()#

Returns a mutable iterator to the first element.

inline generic_graph_node_list_iterator<const T> begin() const#

Returns a read-only iterator to the first element.

inline generic_graph_node_list_iterator<T> end()#

Returns a mutable past-the-end iterator (points at the sentinel).

inline generic_graph_node_list_iterator<const T> end() const#

Returns a read-only past-the-end iterator (points at the sentinel).

inline generic_graph_node_list_iterator<T> rbegin()#

Returns a mutable iterator to the first element of the reverse sequence.

inline generic_graph_node_list_iterator<const T> rbegin() const#

Returns a read-only iterator to the first element of the reverse sequence.

inline generic_graph_node_list_iterator<T> rend()#

Returns a mutable past-the-end iterator for the reverse sequence.

inline generic_graph_node_list_iterator<const T> rend() const#

Returns a read-only past-the-end iterator for the reverse sequence.

inline generic_graph_node_list reverse()#

Returns a view of the same list traversed in the opposite direction.

The returned object shares the same sentinel head but uses the opposite direction index, so iterating it yields nodes in reverse order.

Returns:

A generic_graph_node_list with the direction index flipped.

inline generic_graph_node_list reverse() const#
inline generic_graph_node_list(T *head, size_t d)#

Constructs a list view from a sentinel head pointer and a direction.

Parameters:
  • head – Sentinel node that delimits the list (the “before-first” element).

  • d – Initial traversal direction (kNextDirection or kPrevDirection).

Private Members

T *head#

Sentinel node; its next_in_graph links delimit the list.

size_t d#

Traversal direction: 0 = forward, 1 = reverse.

template<typename T>
struct generic_graph_node_list_iterator#
#include <graph_node_list.h>

Bidirectional iterator for generic_graph_node_list.

The iterator stores a raw pointer to the current node and a direction index so that the same class serves both forward and reverse traversal. Incrementing follows the kNextDirection links; decrementing follows the opposite direction.

Template Parameters:

T – Element type, either Node or const Node.

Public Functions

inline generic_graph_node_list_iterator()#

Constructs an iterator that compares equal to a default-constructed end().

inline generic_graph_node_list_iterator(T *cur, size_t d)#

Constructs an iterator pointing at cur traversing in direction d.

Parameters:
  • cur – Pointer to the current node (may be the sentinel head).

  • d – Traversal direction: kNextDirection (0) or kPrevDirection (1).

inline T *operator*() const#

Dereferences the iterator.

Returns:

Pointer to the current node.

inline T *operator->() const#

Arrow dereference.

Returns:

Pointer to the current node.

inline generic_graph_node_list_iterator &operator++()#

Pre-increment: advances to the next node in the traversal direction.

Returns:

Reference to this iterator after the advance.

inline generic_graph_node_list_iterator operator++(int)#

Post-increment: advances to the next node and returns the previous state.

Returns:

Copy of this iterator before the advance.

inline generic_graph_node_list_iterator &operator--()#

Pre-decrement: moves to the preceding node in the traversal direction.

Returns:

Reference to this iterator after the move.

inline generic_graph_node_list_iterator operator--(int)#

Post-decrement: moves to the preceding node and returns the previous state.

Returns:

Copy of this iterator before the move.

inline void destroyCurrent()#

Destroys the current node without invalidating this iterator.

After the call, the iterator points to the node that preceded the destroyed node in the traversal direction. Named destroyCurrent (rather than destroy) so that accidental -> / . mixups do not silently call the wrong function.

inline generic_graph_node_list_iterator reverse()#

Returns an iterator that traverses in the opposite direction, still pointing at the same node.

Returns:

A new iterator with the direction index flipped.

Private Functions

inline size_t reverseDir()#

Returns the direction index opposite to the current traversal direction.

Private Members

T *cur#

Pointer to the node currently pointed at.

size_t d#

Traversal direction: 0 = forward (next), 1 = reverse (prev).

namespace std#
template<typename T>
struct iterator_traits<ONNX_LIGHT_NAMESPACE::generic_graph_node_list_iterator<T>>#

std::iterator_traits specialisation for generic_graph_node_list_iterator.

Enables standard algorithms and range adaptors to introspect the iterator’s value and difference types. The iterator category is bidirectional_iterator_tag because operator-- is supported but random-access arithmetic is not.

Template Parameters:

T – Element type of the underlying node list.

Public Types

using difference_type = int64_t#

Signed distance between iterators.

using value_type = T*#

Type produced by dereferencing.

using pointer = T**#

Pointer-to-value type.

using reference = T*&#

Reference-to-value type.

using iterator_category = bidirectional_iterator_tag#

Supports ++ and --.