aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::LinkedList< T > Class Template Reference

Chain list allocated using the SmallObjectAllocator. More...

#include <agrum/tools/multidim/FunctionGraphUtilities/link.h>

Public Member Functions

Constructors and Destructors
 LinkedList ()
 Constructor. More...
 
 ~LinkedList ()
 Destructor. More...
 
void * operator new (size_t s)
 Operator new overload to use the SmallObjectAllocator. More...
 
void operator delete (void *p)
 Operator delete overload to use the SmallObjectAllocator. More...
 
Misceleanous methods
const Link< T > * list () const
 Returns the first link in the chained list. More...
 
Link< T > * list ()
 Returns the first link in the chained list. More...
 
void clear ()
 Clears the list. More...
 
void addLink (const T &elem)
 Adds a link. More...
 
void searchAndRemoveLink (const T &elem)
 Removes a element from the list. More...
 

Detailed Description

template<typename T>
class gum::LinkedList< T >

Chain list allocated using the SmallObjectAllocator.

Template Parameters
TThe type stored by the chain list.

Definition at line 134 of file link.h.

Constructor & Destructor Documentation

◆ LinkedList()

template<typename T >
INLINE gum::LinkedList< T >::LinkedList ( )

Constructor.

Definition at line 92 of file link_tpl.h.

92  {
93  GUM_CONSTRUCTOR(LinkedList);
94  _firstLink_ = nullptr;
95  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196
LinkedList()
Constructor.
Definition: link_tpl.h:92

◆ ~LinkedList()

template<typename T >
INLINE gum::LinkedList< T >::~LinkedList ( )

Destructor.

Definition at line 99 of file link_tpl.h.

99  {
100  clear();
101  GUM_DESTRUCTOR(LinkedList);
102  }
void clear()
Clears the list.
Definition: link_tpl.h:125
LinkedList()
Constructor.
Definition: link_tpl.h:92

Member Function Documentation

◆ addLink()

template<typename T>
INLINE void gum::LinkedList< T >::addLink ( const T &  elem)

Adds a link.

Definition at line 136 of file link_tpl.h.

136  {
137  Link< T >* newLink = new Link< T >(elem, _firstLink_);
138  _firstLink_ = newLink;
139  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196

◆ clear()

template<typename T >
void gum::LinkedList< T >::clear ( )

Clears the list.

Definition at line 125 of file link_tpl.h.

125  {
126  Link< T >* curLink = _firstLink_;
127  Link< T >* nl = nullptr;
128  while (curLink) {
129  nl = curLink->nextLink();
130  delete curLink;
131  curLink = nl;
132  }
133  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196

◆ list() [1/2]

template<typename T >
INLINE const Link< T > * gum::LinkedList< T >::list ( ) const

Returns the first link in the chained list.

Definition at line 115 of file link_tpl.h.

115  {
116  return _firstLink_;
117  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196

◆ list() [2/2]

template<typename T >
INLINE Link< T > * gum::LinkedList< T >::list ( )

Returns the first link in the chained list.

Definition at line 120 of file link_tpl.h.

120  {
121  return _firstLink_;
122  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196

◆ operator delete()

template<typename T >
INLINE void gum::LinkedList< T >::operator delete ( void *  p)

Operator delete overload to use the SmallObjectAllocator.

Definition at line 110 of file link_tpl.h.

110  {
111  SmallObjectAllocator::instance().deallocate(p, sizeof(LinkedList< T >));
112  }
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
static SmallObjectAllocator & instance()

◆ operator new()

template<typename T >
INLINE void * gum::LinkedList< T >::operator new ( size_t  s)

Operator new overload to use the SmallObjectAllocator.

Definition at line 105 of file link_tpl.h.

105  {
107  }
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

◆ searchAndRemoveLink()

template<typename T>
INLINE void gum::LinkedList< T >::searchAndRemoveLink ( const T &  elem)

Removes a element from the list.

Definition at line 142 of file link_tpl.h.

142  {
143  Link< T >* curLink = _firstLink_;
144  Link< T >* prevLink = nullptr;
145  while (curLink && curLink->element() != elem) {
146  prevLink = curLink;
147  curLink = curLink->nextLink();
148  }
149  if (curLink) {
150  if (prevLink)
151  prevLink->setNextLink(curLink->nextLink());
152  else
153  _firstLink_ = curLink->nextLink();
154  delete curLink;
155  }
156  }
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196

Member Data Documentation

◆ _firstLink_

template<typename T>
Link< T >* gum::LinkedList< T >::_firstLink_
private

The first link of our list.

Definition at line 196 of file link.h.


The documentation for this class was generated from the following files: