aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
link_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
52
54
55namespace gum {
56
57 // Constructor
58 template < typename T >
59 INLINE Link< T >::Link(const T& elem) : _element_(elem) {
60 GUM_CONSTRUCTOR(Link);
61 }
62
63 // Constructor
64 template < typename T >
65 INLINE Link< T >::Link(const T& elem, Link< T >* nextLink) :
67 GUM_CONSTRUCTOR(Link);
68 }
69
70 // Destructor
71 template < typename T >
73 GUM_DESTRUCTOR(Link);
74 }
75
76 template < typename T >
77 INLINE void* Link< T >::operator new(size_t s) {
79 }
80
81 template < typename T >
82 INLINE void Link< T >::operator delete(void* p) {
84 }
85
86 template < typename T >
87 INLINE const T& Link< T >::element() const {
88 return _element_;
89 }
90
91 template < typename T >
92 INLINE T& Link< T >::element() {
93 return _element_;
94 }
95
96 template < typename T >
97 INLINE const Link< T >* Link< T >::nextLink() const {
98 return _nextLink_;
99 }
100
101 template < typename T >
103 return _nextLink_;
104 }
105
106 template < typename T >
107 INLINE void Link< T >::setNextLink(Link< T >* newLink) {
108 _nextLink_ = newLink;
109 }
110
111 // Constructor
112 template < typename T >
114 GUM_CONSTRUCTOR(LinkedList);
115 _firstLink_ = nullptr;
116 }
117
118 // Destructor
119 template < typename T >
121 clear();
122 GUM_DESTRUCTOR(LinkedList);
124
125 template < typename T >
126 INLINE void* LinkedList< T >::operator new(size_t s) {
128 }
129
130 template < typename T >
134
135 template < typename T >
136 INLINE const Link< T >* LinkedList< T >::list() const {
137 return _firstLink_;
138 }
139
140 template < typename T >
142 return _firstLink_;
143 }
144
145 template < typename T >
147 Link< T >* curLink = _firstLink_;
148 Link< T >* nl = nullptr;
149 while (curLink) {
150 nl = curLink->nextLink();
151 delete curLink;
152 curLink = nl;
153 }
154 }
155
156 template < typename T >
157 INLINE void LinkedList< T >::addLink(const T& elem) {
158 Link< T >* newLink = new Link< T >(elem, _firstLink_);
159 _firstLink_ = newLink;
160 }
161
162 template < typename T >
163 INLINE void LinkedList< T >::searchAndRemoveLink(const T& elem) {
164 Link< T >* curLink = _firstLink_;
165 Link< T >* prevLink = nullptr;
166 while (curLink && curLink->element() != elem) {
167 prevLink = curLink;
168 curLink = curLink->nextLink();
169 }
170 if (curLink) {
171 if (prevLink) prevLink->setNextLink(curLink->nextLink());
172 else _firstLink_ = curLink->nextLink();
173 delete curLink;
174 }
176
177} // namespace gum
Chain list allocated using the SmallObjectAllocator.
Definition link.h:155
~LinkedList()
Destructor.
Definition link_tpl.h:120
void searchAndRemoveLink(const T &elem)
Removes a element from the list.
Definition link_tpl.h:163
void clear()
Clears the list.
Definition link_tpl.h:146
const Link< T > * list() const
Returns the first link in the chained list.
Definition link_tpl.h:136
Link< T > * _firstLink_
The first link of our list.
Definition link.h:217
LinkedList()
Constructor.
Definition link_tpl.h:113
void addLink(const T &elem)
Adds a link.
Definition link_tpl.h:157
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
gum is the global namespace for all aGrUM entities
Definition agrum.h:46