annotate egglib/egglib-2.1.5/include/egglib-cpp/Edge.hpp @ 1:420b57c3c185 draft

Uploaded
author dereeper
date Fri, 10 Jul 2015 04:39:30 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
1 /*
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
2 Copyright 2009-2010 Stéphane De Mita, Mathieu Siol
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
3
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
4 This file is part of the EggLib library.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
5
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
6 EggLib is free software: you can redistribute it and/or modify
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
8 the Free Software Foundation, either version 3 of the License, or
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
9 (at your option) any later version.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
10
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
11 EggLib is distributed in the hope that it will be useful,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
14 GNU General Public License for more details.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
15
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
17 along with EggLib. If not, see <http://www.gnu.org/licenses/>.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
18 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
19
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
20 #ifndef EGGLIB_EDGE_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
21 #define EGGLIB_EDGE_HPP
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
22
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
23 #include <vector>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
24 #include <climits>
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
25 #include "EggException.hpp"
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
26
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
27 namespace egglib {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
28
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
29 class Random;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
30
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
31 /** \brief Edge of the ancestral recombination graph
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
32 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
33 * \ingroup coalesce
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
34 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
35 * Each Edge instance provides access to its 0, 1 or 2 descendants
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
36 * (the former holds for a terminal node, the middle for the parent
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
37 * of a recombined node and the latter for the parent of a coalesced
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
38 * node (most classical node in the coalescent).The Edge also
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
39 * provides to the edge length. Note that the Edge instance must be
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
40 * understood as an ARG node and the branch above it (latter in the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
41 * coalescence process). Edge instances also keep track of the list
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
42 * of descendants descending from this node (which may differ along
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
43 * recombining segment). Edge instances *must* be created through one
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
44 * of the "default" and "coalescence" constructors or through the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
45 * recombination method. Edge instances should never be copied but
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
46 * manipulated by references.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
47 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
48 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
49 class Edge {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
50
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
51 public:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
52
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
53 /// Destructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
54 virtual ~Edge();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
55
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
56 /** \brief Constructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
57 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
58 * \param numberOfSegments the number of recombining segments
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
59 * (one for a non-recombining region).
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
60 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
61 * Use the Pool, instead. Objects are delivered with a
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
62 * complete coverage.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
63 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
64 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
65 Edge(unsigned int numberOfSegments);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
66
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
67
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
68 /// Restore object to `factory` state
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
69 void reset();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
70
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
71
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
72 /** \brief Builds for internal node
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
73 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
74 * \param date the date of creation of the edge.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
75 * \param son1 first edge descending from this edge.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
76 * \param son2 second edge descending from this edge.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
77 * \param edgesPerSegments counts the current number of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
78 * (non-coalesced lineages for each lineages); must have the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
79 * appropriate size and will be updated.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
80 * \param MRCA the list where to place the address of segment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
81 * MRCA, if it occurs.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
82 * \param totalLength the total length of the tree.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
83 * \param segmentLengths the table of tree lengths per
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
84 * segment.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
85 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
86 * Assumes the current object has the correct number of
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
87 * segments.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
88 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
89 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
90 void coalescence(double date, Edge* son1, Edge* son2,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
91 unsigned int* edgesPerSegments, Edge** MRCA,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
92 double& totalLength, double* segmentLengths);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
93
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
94
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
95 /** \brief Generates a recombination event
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
96 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
97 * \param date the date of the event.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
98 * \param dest1 destination for the first resulting edge.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
99 * \param dest2 destination for the second resulting edge.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
100 * \param random pointer to the Random instance used by the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
101 * simulator.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
102 * \param totalLength the total length of the tree.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
103 * \param segmentLengths the table of tree lengths per
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
104 * segment.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
105 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
106 * dest1 and dest2 must be Edge address initialized with the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
107 * appropriate number of segments.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
108 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
109 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
110 void recombination(double date,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
111 Edge* dest1, Edge* dest2, Random* random,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
112 double& totalLength, double* segmentLengths);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
113
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
114
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
115 /** \brief Define this edge to be terminal
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
116 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
117 * The edge have only non-covered segments
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
118 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
119 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
120 void set_terminal(unsigned int leaf_index);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
121
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
122 /// Branch's raw length (doesn't take account segment coverage)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
123 double length;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
124
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
125 /// Number of covered segments
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
126 unsigned int coverage;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
127
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
128 /// Time position of the branch's bottom
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
129 double bottom;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
130
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
131 /// Time position of the branch's top
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
132 double top;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
133
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
134 /// Address of the first son
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
135 Edge* son1;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
136
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
137 /// Address of the second son
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
138 Edge* son2;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
139
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
140 /// Number of sons (0, 1 or 2)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
141 unsigned int numberOfSons;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
142
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
143 /// Checks if a given segment is covered
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
144 inline bool segment(unsigned int segmentIndex) const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
145 //while(segments[segmentIndex]==0) segmentIndex--;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
146 if (segments[segmentIndex]==0) return false;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
147 if (segments[segmentIndex]==UINT_MAX) return true;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
148 return segbools[segmentIndex];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
149 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
150
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
151 /// leaf index (0 for internal nodes)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
152 inline unsigned int label() const {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
153 return _label;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
154 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
155
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
156 /// Number of mutations per segment
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
157 unsigned int* numberOfMutationsPerActualSite;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
158
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
159 /// Sets the actual number of sites
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
160 void set_actualNumberOfSites(unsigned int actualNumberOfSites);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
161
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
162
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
163 private:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
164
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
165 unsigned int _label;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
166
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
167 /// Default constructor is not available
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
168 Edge();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
169
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
170 /// Copy constructor is not available
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
171 Edge(const Edge& edge) {}
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
172
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
173 /// Assignment operator is not available
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
174 Edge& operator=(const Edge& edge) { return *this; }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
175
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
176 void init(unsigned int numberOfSegments);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
177
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
178 unsigned int numberOfSegments;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
179 unsigned int* segments;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
180 bool* segbools;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
181
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
182 /// complete the covered ranges with UINT_MAX's and the non-covered by 0's
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
183 inline void fill() {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
184 coverage=0.;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
185 unsigned int i=0,j;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
186 while (i<numberOfSegments) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
187 if (segbools[i]==true) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
188 coverage += segments[i];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
189 for (j=1; j<segments[i]; j++) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
190 segments[i+j] = UINT_MAX;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
191 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
192 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
193 i+=segments[i];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
194 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
195 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
196
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
197
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
198
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
199 /// update containing Arg's branch lengths
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
200 inline void update_lengths(double& totalLength, double* segmentLengths) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
201 unsigned int i=0,j;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
202 while (i<numberOfSegments) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
203 if (segbools[i]==true) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
204 totalLength += segments[i]*length;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
205 for (j=0; j<segments[i]; j++) {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
206 segmentLengths[i+j] += length;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
207 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
208 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
209 i+=segments[i];
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
210 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
211 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
212
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
213
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
214 };
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
215
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
216
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
217
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
218
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
219
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
220
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
221
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
222
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
223
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
224
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
225
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
226
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
227 /** \brief Pool of Edge objects
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
228 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
229 * \ingroup coalesce
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
230 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
231 * Holds a pool of Edge objects that can be recycled to spare the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
232 * building burden. A construction time, a number of Edge objects
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
233 * equals to the predicted number of needed instances should be
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
234 * requested. The Edge's will be prebuilt immediately and delivered
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
235 * upon request. After use, the Edge's should be released. It is only
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
236 * possible to release the last issued Edge instance or all of them
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
237 * at once.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
238 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
239 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
240 class EdgePool {
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
241
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
242 public:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
243
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
244 /// Default constructor (nothing allocated)
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
245 EdgePool();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
246
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
247
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
248 /// Destructor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
249 virtual ~EdgePool();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
250
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
251
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
252 /** \brief Configure pool
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
253 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
254 * Pre-allocates a given number of Edge objects. The objects
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
255 * will be immediately available.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
256 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
257 * Data previously allocated (by a previous call of this
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
258 * function or by the deliver() method) will be lost so it
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
259 * can be required to use clear() before.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
260 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
261 * \param numberOfSegments the number of segments of the
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
262 * simulation; all Edge instances will use this value.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
263 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
264 * \param numberOfPreAllocated the number of Edge that should
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
265 * be kept ready for immediate use.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
266 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
267 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
268 void set(unsigned int numberOfSegments, unsigned numberOfPreAllocated);
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
269
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
270
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
271 /** \brief Frees internally stored memory
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
272 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
273 * This invalidate all points that have been delivered
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
274 * previously. However, any previously set number of segments
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
275 * (0, by default) is retained.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
276 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
277 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
278 void clear();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
279
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
280
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
281 /** \brief Deliver an Edge
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
282 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
283 * The object must not be freed by the client! This object is
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
284 * allocated on the heap if the cache is not large enough,
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
285 * only reset if it was previously released, or just delivered
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
286 * if it is one of the initially allocated instances.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
287 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
288 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
289 Edge* deliver();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
290
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
291
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
292 /** \brief Release an Edge
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
293 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
294 * Release the last delivered Edge. The instance is only
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
295 * cached for a potential future use; it is not freed nor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
296 * reset immediately. If no Edge's are in use, nothing is
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
297 * done.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
298 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
299 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
300 void releaseLast();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
301
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
302
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
303 /** \brief Release all Edge's
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
304 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
305 * Release all delivered Edges. The instances are only
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
306 * cached for a potential future use; they are not freed nor
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
307 * reset immediately. If no Edge's are in use, nothing is
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
308 * done.
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
309 *
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
310 */
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
311 void releaseAll();
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
312
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
313 private:
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
314
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
315 /// Not available
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
316 EdgePool(const EdgePool& ep) {}
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
317
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
318 /// Not available
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
319 EdgePool& operator=(const EdgePool& ep) { return *this; }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
320
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
321 unsigned int numberOfSegments;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
322 unsigned int used;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
323 unsigned int released;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
324 unsigned int ready;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
325 Edge** cache;
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
326
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
327 };
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
328
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
329 }
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
330
420b57c3c185 Uploaded
dereeper
parents:
diff changeset
331 #endif