Make queue trim by factors

Previously, queue would trim every 64 pops. However, this does not make sense for a queue with thousands of elements. Thus, now queue trims every time that the amount of trims times 1.5 is greater or equal to the size of the queue.
This commit is contained in:
Bailey Thompson
2018-01-24 21:28:13 -05:00
committed by GitHub
parent b20837d83a
commit 00b849c42f
3 changed files with 19 additions and 5 deletions

View File

@@ -39,4 +39,17 @@ void test_queue(void)
assert(!queue_back(&get, me));
me = queue_destroy(me);
assert(!me);
me = queue_init(sizeof(int));
assert(me);
for (int i = 123; i < 123456; i++) {
queue_push(me, &i);
}
const int old_size = queue_size(me);
int pop_count = 0;
while (!queue_is_empty(me)) {
queue_pop(&get, me);
pop_count++;
}
assert(pop_count == old_size);
queue_destroy(me);
}