Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/gpgmm/utils/StableList.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ namespace gpgmm {
return mIndex;
}

StableListT* list() const {
return mList;
}

protected:
StableListT* mList;
size_t mIndex;
Expand Down Expand Up @@ -379,11 +383,17 @@ namespace gpgmm {
StableListIteratorBase<StableList<T, ChunkSize>>::operator++();
return *this;
}

iterator operator+(int offset) const {
iterator tmp = *this;
tmp.mIndex += offset;
return tmp;
}
};

struct const_iterator : public StableListIteratorBase<const StableList<T, ChunkSize>> {
const_iterator(const iterator& it)
: StableListIteratorBase<const StableList<T, ChunkSize>>(it.mList, it.mIndex) {
: StableListIteratorBase<const StableList<T, ChunkSize>>(it.list(), it.index()) {
}

const_iterator(StableList<T, ChunkSize> const* list, size_t index)
Expand All @@ -406,10 +416,16 @@ namespace gpgmm {
StableListIteratorBase<const StableList<T, ChunkSize>>::operator++();
return *this;
}

const_iterator operator+(int offset) const {
const_iterator tmp = *this;
tmp.mIndex += offset;
return tmp;
}
};

void erase(const_iterator it) {
erase(it.mIndex);
erase(it.index());
}

iterator begin() {
Expand Down
11 changes: 11 additions & 0 deletions src/tests/unittests/StableListTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ TEST(StableListTests, Insert) {
EXPECT_EQ(list[2], 0);
}

TEST(StableListTests, Get) {
StableList<int, 2> list;
list.push_back(0);
list.push_back(1);
list.push_back(2);

EXPECT_EQ(*list.begin(), 0);
EXPECT_EQ(*list.begin() + 1, 1);
EXPECT_EQ(*list.begin() + 2, 2);
}

TEST(StableListTests, RemoveEnds) {
StableList<int> list;
list.push_back(0);
Expand Down