[Glacier] Allow removing from an intrusive list.
This commit is contained in:
parent
961389dee8
commit
66e94ac41b
|
@ -20,6 +20,8 @@ class IntrusiveList {
|
||||||
void PushFront(const RefPtr<T>& obj);
|
void PushFront(const RefPtr<T>& obj);
|
||||||
void PushBack(const RefPtr<T>& obj);
|
void PushBack(const RefPtr<T>& obj);
|
||||||
|
|
||||||
|
void Remove(const RefPtr<T>& obj);
|
||||||
|
|
||||||
RefPtr<T> PopFront();
|
RefPtr<T> PopFront();
|
||||||
RefPtr<T> PopBack();
|
RefPtr<T> PopBack();
|
||||||
|
|
||||||
|
@ -64,6 +66,29 @@ void IntrusiveList<T>::PushBack(const RefPtr<T>& obj) {
|
||||||
back_ = obj;
|
back_ = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void IntrusiveList<T>::Remove(const RefPtr<T>& obj) {
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (front_ == obj) {
|
||||||
|
front_ = obj->next_;
|
||||||
|
}
|
||||||
|
if (back_ == obj) {
|
||||||
|
back_ = obj->prev_;
|
||||||
|
}
|
||||||
|
if (obj->prev_) {
|
||||||
|
obj->prev_->next_ = obj->next_;
|
||||||
|
}
|
||||||
|
if (obj->next_) {
|
||||||
|
obj->next_->prev_ = obj->prev_;
|
||||||
|
}
|
||||||
|
|
||||||
|
obj->prev_ = nullptr;
|
||||||
|
obj->next_ = nullptr;
|
||||||
|
size_--;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
RefPtr<T> IntrusiveList<T>::PopFront() {
|
RefPtr<T> IntrusiveList<T>::PopFront() {
|
||||||
if (front_ == nullptr) {
|
if (front_ == nullptr) {
|
||||||
|
|
Loading…
Reference in New Issue