From 3fdedc4768ab0d097dc674f39a08941405ce1e90 Mon Sep 17 00:00:00 2001 From: Stathis Kamperis Date: Sat, 12 Jan 2008 23:37:04 +0100 Subject: [PATCH] Add print_array_stats() --- proplib/prop_expand.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/proplib/prop_expand.c b/proplib/prop_expand.c index 046d3e9..aeaa131 100644 --- a/proplib/prop_expand.c +++ b/proplib/prop_expand.c @@ -7,6 +7,9 @@ #define NUM_STRINGS 32 #define PRINT_STEP 5 /* Print stats every 5 steps */ +/* Function prototypes */ +void print_array_stats(const prop_array_t pa); + int main(int argc, char *argv[]) { @@ -38,11 +41,8 @@ main(int argc, char *argv[]) */ for (i = 0; i < NUM_STRINGS; i++) { /* Print statistics every ``PRINT_STEP'' step */ - if (i % PRINT_STEP == 0) { - printf("count = %u\tcapacity = %u\n", - prop_array_count(pa), - prop_array_capacity(pa)); - } + if (i % PRINT_STEP == 0) + print_array_stats(pa); /* Add object reference in array */ if (prop_array_add(pa, ps) == FALSE) { @@ -52,14 +52,32 @@ main(int argc, char *argv[]) } } + /* + * Remove references from array and note that + * if an expansion has happened before, array's + * capacity won't reduce to its initial value, + * i.e. ``INIT_CAPACITY'' + */ for (i = 0; i < NUM_STRINGS; i++) { - printf("%u\n", prop_array_capacity(pa)); - prop_array_remove(pa, i); + /* Print statistics every ``PRINT_STEP'' step */ + if (i % PRINT_STEP == 0) + print_array_stats(pa); + + prop_array_remove(pa, NUM_STRINGS - i - 1); } /* Release objects */ prop_object_release(pa); prop_object_release(ps); + print_array_stats(pa); + return EXIT_SUCCESS; } + +void print_array_stats(const prop_array_t pa) +{ + printf("count = %u\tcapacity = %u\n", + prop_array_count(pa), + prop_array_capacity(pa)); +} -- 2.11.4.GIT