mirror of
https://github.com/bkthomps/Containers.git
synced 2025-11-16 12:34:47 +00:00
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:
13
tst/queue.c
13
tst/queue.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user