Skip to content

Commit

Permalink
Addition of pointer based methods to FlatSet data, at and operator[]
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Jun 13, 2021
1 parent 843b90b commit 57c7a48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/include/amc_flatset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ class FlatSet : private Compare {
const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); }
const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); }

const_pointer data() const noexcept { return _sortedVector.data(); }

const_reference operator[](size_type idx) const { return _sortedVector[idx]; }

const_reference at(size_type idx) const { return _sortedVector.at(idx); }

bool empty() const noexcept { return _sortedVector.empty(); }
size_type size() const noexcept { return _sortedVector.size(); }
size_type max_size() const noexcept { return _sortedVector.max_size(); }
Expand Down
10 changes: 10 additions & 0 deletions src/test/sets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ TEST(FlatSetTest, MergeDifferentCompare) {
EXPECT_EQ(s2, RevSetType({19, 4, 2, -2}));
}

TEST(FlatSetTest, SpecificPointerMethods) {
using SetType = FlatSet<int>;
SetType s{-2, 0, 2, 3, 4, 6, 19};
const SetType::value_type* pValue = s.data(); // to ensure return type of data() is a pointer
EXPECT_EQ(pValue[0], -2);
EXPECT_EQ(s[1], 0);
EXPECT_EQ(s.at(2), 2);
EXPECT_THROW(s.at(7), std::out_of_range);
}

#ifdef AMC_SMALLSET
TEST(SmallSetTest, MergeDifferentCompare) {
using SetType = SmallSet<char, 20, std::less<char>>;
Expand Down

0 comments on commit 57c7a48

Please sign in to comment.