pool: add 'full' query

This commit is contained in:
Danny Robson 2019-01-21 17:13:47 +11:00
parent d73332034f
commit 41c9b504dc
2 changed files with 22 additions and 2 deletions

View File

@ -144,6 +144,7 @@ namespace cruft {
auto capacity (void) const { return m_capacity; }
auto size (void) const { return m_size.load (); }
bool empty (void) const { return size () == 0; }
bool full (void) const { return size () == capacity (); }
// Indexing

View File

@ -28,7 +28,7 @@ check_unique_ptr (cruft::TAP::logger &tap)
std::set<uint64_t *> uintset;
// Take all pointers out, checking they are unique, then replace for destruction.
while (!uintpool.empty ())
while (!uintpool.full ())
uintset.insert (uintpool.allocate ());
tap.expect_eq (uintset.size (), uintpool.capacity (), "extracted maximum elements");
@ -40,7 +40,7 @@ check_unique_ptr (cruft::TAP::logger &tap)
uintset.clear ();
// Do the above one more time to ensure that releasing works right
while (!uintpool.empty ())
while (!uintpool.full ())
uintset.insert (uintpool.allocate ());
tap.expect_eq (uintset.size (), uintpool.capacity (), "re-extracted maximum elements");
}
@ -120,6 +120,24 @@ done:
}
//-----------------------------------------------------------------------------
void
check_size_queries (cruft::TAP::logger &tap)
{
cruft::pool<int> data (8);
tap.expect_eq (data.size (), 0u, "initial size is zero");
tap.expect (data.empty (), "initial object is empty");
auto first = data.allocate ();
tap.expect_eq (data.size (), 1u, "1 allocation has size of 1");
tap.expect (!data.empty (), "1 allocation is not empty");
data.deallocate (first);
tap.expect (data.empty (), "full deallocation is empty");
}
//-----------------------------------------------------------------------------
int
main (int, char **)
@ -129,5 +147,6 @@ main (int, char **)
check_unique_ptr (tap);
check_keep_value (tap);
check_keep_variadic_value (tap);
check_size_queries (tap);
});
}