Skip to content

Commit

Permalink
dlist::insert_before/after
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobR authored and NikolajBjorner committed Aug 1, 2022
1 parent de6a0ab commit e8e64d3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/util/dlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ class dll_base {
remove_from(list, head);
return head;
}

void insert_after(T* elem) {
T* next = this->m_next;
elem->m_prev = next->m_prev;
elem->m_next = next;
this->m_next = elem;
next->m_prev = elem;
}

void insert_before(T* elem) {
T* prev = this->m_prev;
elem->m_next = prev->m_next;
elem->m_prev = prev;
prev->m_next = elem;
this->m_prev = elem;
}

static void remove_from(T*& list, T* elem) {
if (list->m_next == list) {
Expand Down

0 comments on commit e8e64d3

Please sign in to comment.