MCPcopy Create free account
hub / github.com/davisking/dlib / add

Method add

dlib/sequence/sequence_kernel_2.h:251–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249 typename mem_manager
250 >
251 void sequence_kernel_2<T,mem_manager>::
252 add (
253 unsigned long pos,
254 T& item
255 )
256 {
257 // make new node and swap item into it
258 node* new_node = new node;
259 exchange(item,new_node->item);
260
261 if (sequence_size > 0)
262 {
263 if (pos == sequence_size)
264 {
265 move_to_pos(current_node,current_pos,pos-1,sequence_size);
266
267 node& n_node = *new_node;
268 node& c_node = *current_node;
269
270 // make new node point to the nodes to its left and right
271 n_node.right = c_node.right;
272 n_node.left = current_node;
273
274 // make the left node point back to new_node
275 c_node.right->left = new_node;
276
277 // make the right node point back to new_node
278 c_node.right = new_node;
279 current_pos = pos;
280
281 }
282 else
283 {
284 move_to_pos(current_node,current_pos,pos,sequence_size);
285
286 node& n_node = *new_node;
287 node& c_node = *current_node;
288
289 // make new node point to the nodes to its left and right
290 n_node.right = current_node;
291 n_node.left = c_node.left;
292
293 // make the left node point back to new_node
294 c_node.left->right = new_node;
295
296 // make the right node point back to new_node
297 c_node.left = new_node;
298 }
299
300 }
301 else
302 {
303 current_pos = 0;
304 new_node->left = new_node;
305 new_node->right = new_node;
306 }
307
308 // make the new node the current node

Callers

nothing calls this directly

Calls 2

exchangeFunction · 0.85
resetFunction · 0.85

Tested by

no test coverage detected