Revert "Revert "Fix dlsym(3) to do breadth first search.""

This reverts commit 1b1966d944.

Change-Id: I05d6d3481aaf8f3e260d2e5e950248519a1d347f
This commit is contained in:
Dmitriy Ivanov
2014-08-04 23:39:22 +00:00
parent 1b1966d944
commit db7a17d4ff
7 changed files with 128 additions and 19 deletions

View File

@@ -31,13 +31,45 @@ struct LinkedListEntry {
template<typename T, typename Allocator>
class LinkedList {
public:
LinkedList() : head_(nullptr) {}
LinkedList() : head_(nullptr), tail_(nullptr) {}
void push_front(T* const element) {
LinkedListEntry<T>* new_entry = Allocator::alloc();
new_entry->next = head_;
new_entry->element = element;
head_ = new_entry;
if (tail_ == nullptr) {
tail_ = new_entry;
}
}
void push_back(T* const element) {
LinkedListEntry<T>* new_entry = Allocator::alloc();
new_entry->next = nullptr;
new_entry->element = element;
if (tail_ == nullptr) {
tail_ = head_ = new_entry;
} else {
tail_->next = new_entry;
tail_ = new_entry;
}
}
T* pop_front() {
if (head_ == nullptr) {
return nullptr;
}
LinkedListEntry<T>* entry = head_;
T* element = entry->element;
head_ = entry->next;
Allocator::free(entry);
if (head_ == nullptr) {
tail_ = nullptr;
}
return element;
}
void clear() {
@@ -46,6 +78,8 @@ class LinkedList {
head_ = head_->next;
Allocator::free(p);
}
tail_ = nullptr;
}
template<typename F>
@@ -68,6 +102,7 @@ class LinkedList {
private:
LinkedListEntry<T>* head_;
LinkedListEntry<T>* tail_;
DISALLOW_COPY_AND_ASSIGN(LinkedList);
};