intrusive_list: Add insert_before() and insert_after() helper functions
Small helpers for inserting nodes before and after an existing one. insert() is the same as insert_before(), so insert() is just made to be an alias of this.
This commit is contained in:
parent
8d1b9f32ca
commit
46573eb538
1 changed files with 24 additions and 0 deletions
|
@ -132,6 +132,17 @@ public:
|
||||||
* @param new_node The node to add.
|
* @param new_node The node to add.
|
||||||
*/
|
*/
|
||||||
iterator insert(iterator location, pointer new_node) {
|
iterator insert(iterator location, pointer new_node) {
|
||||||
|
return insert_before(location, new_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a node at the given location, moving the previous
|
||||||
|
* node occupant ahead of the one inserted.
|
||||||
|
*
|
||||||
|
* @param location The location to insert the new node.
|
||||||
|
* @param new_node The node to insert into the list.
|
||||||
|
*/
|
||||||
|
iterator insert_before(iterator location, pointer new_node) {
|
||||||
auto existing_node = location.AsNodePointer();
|
auto existing_node = location.AsNodePointer();
|
||||||
|
|
||||||
new_node->next = existing_node;
|
new_node->next = existing_node;
|
||||||
|
@ -142,6 +153,19 @@ public:
|
||||||
return iterator(root.get(), new_node);
|
return iterator(root.get(), new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a new node into the list ahead of the position indicated.
|
||||||
|
*
|
||||||
|
* @param position Location to insert the node in front of.
|
||||||
|
* @param new_node The node to be inserted into the list.
|
||||||
|
*/
|
||||||
|
iterator insert_after(iterator position, pointer new_node) {
|
||||||
|
if (empty())
|
||||||
|
return insert(begin(), new_node);
|
||||||
|
|
||||||
|
return insert(++position, new_node);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an entry to the start of the list.
|
* Add an entry to the start of the list.
|
||||||
* @param node Node to add to the list.
|
* @param node Node to add to the list.
|
||||||
|
|
Loading…
Reference in a new issue