Commit 7ce33845 authored by Marc Celani's avatar Marc Celani Committed by Sara Golemon

sorted_vector containers have a shrink_to_fit() method

Summary: Adds a shrink_to_fit() method to sorted vector types.

Test Plan: unit test

Reviewed By: mshneer@fb.com

FB internal diff: D1477864
parent 2215f6c0
......@@ -241,6 +241,7 @@ public:
size_type max_size() const { return m_.cont_.max_size(); }
bool empty() const { return m_.cont_.empty(); }
void reserve(size_type s) { return m_.cont_.reserve(s); }
void shrink_to_fit() { m_.cont_.shrink_to_fit(); }
size_type capacity() const { return m_.cont_.capacity(); }
std::pair<iterator,bool> insert(const value_type& value) {
......@@ -484,6 +485,7 @@ public:
size_type max_size() const { return m_.cont_.max_size(); }
bool empty() const { return m_.cont_.empty(); }
void reserve(size_type s) { return m_.cont_.reserve(s); }
void shrink_to_fit() { m_.cont_.shrink_to_fit(); }
size_type capacity() const { return m_.cont_.capacity(); }
std::pair<iterator,bool> insert(const value_type& value) {
......
......@@ -319,3 +319,17 @@ TEST(SortedVectorTest, MoveTest) {
EXPECT_EQ(*m[5], 5);
EXPECT_EQ(*m[10], 10);
}
TEST(SortedVectorTest, ShrinkTest) {
sorted_vector_set<int> s;
int i = 0;
// Hopefully your resize policy doubles when capacity is full, or this will
// hang forever :(
while (s.capacity() == s.size()) {
s.insert(i++);
}
s.shrink_to_fit();
// The standard does not actually enforce that this be true, but assume that
// vector::shrink_to_fit respects the caller.
EXPECT_EQ(s.capacity(), s.size());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment