From db094810fd899a7eec68646db2e2319f26b71337 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 30 May 2012 19:55:17 -0700 Subject: [PATCH] removing quicklist, importing it from a submodule --- src/bindings/bind_faction.c | 2 +- src/bindings/bind_unit.c | 2 +- src/bindings/bindings.c | 2 +- src/build/util.c | 1 - src/gamecode/creport.c | 2 +- src/gamecode/laws.c | 2 +- src/gamecode/market.c | 2 +- src/gamecode/report.c | 2 +- src/gamecode/spy.c | 2 +- src/gamecode/xmlreport.c | 2 +- src/kernel/alliance.c | 2 +- src/kernel/battle.c | 2 +- src/kernel/building.c | 2 +- src/kernel/config.c | 2 +- src/kernel/connection.c | 2 +- src/kernel/curse.c | 2 +- src/kernel/equipment.c | 2 +- src/kernel/equipment_test.c | 2 +- src/kernel/faction.c | 2 +- src/kernel/magic.c | 2 +- src/kernel/magic_test.c | 2 +- src/kernel/pathfinder.c | 2 +- src/kernel/reports.c | 2 +- src/kernel/save.c | 2 +- src/kernel/ship.c | 2 +- src/kernel/spell.c | 2 +- src/kernel/spell_test.c | 2 +- src/kernel/spellbook.c | 2 +- src/kernel/spellbook_test.c | 2 +- src/modules/autoseed.c | 2 +- src/modules/wormhole.c | 2 +- src/tests.c | 2 - src/util/quicklist.c | 256 ------------------------------------ src/util/quicklist.h | 45 ------- src/util/quicklist_test.c | 203 ---------------------------- 35 files changed, 30 insertions(+), 537 deletions(-) delete mode 100644 src/util/quicklist.c delete mode 100644 src/util/quicklist.h delete mode 100644 src/util/quicklist_test.c diff --git a/src/bindings/bind_faction.c b/src/bindings/bind_faction.c index 665af06d6..111b49f37 100644 --- a/src/bindings/bind_faction.c +++ b/src/bindings/bind_faction.c @@ -27,7 +27,7 @@ without prior permission by the authors of Eressea. #include #include -#include +#include #include #include diff --git a/src/bindings/bind_unit.c b/src/bindings/bind_unit.c index 50c588e78..8949ddb66 100644 --- a/src/bindings/bind_unit.c +++ b/src/bindings/bind_unit.c @@ -44,7 +44,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index ed0c2fc40..e12c1756b 100644 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -57,7 +57,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include #include diff --git a/src/build/util.c b/src/build/util.c index 7175b9dec..3fa1e4f1c 100644 --- a/src/build/util.c +++ b/src/build/util.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index cfd718985..94abc0294 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -64,7 +64,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index ab79b4122..2f1e0b252 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -78,7 +78,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/gamecode/market.c b/src/gamecode/market.c index d49e528b6..2e812e9c0 100644 --- a/src/gamecode/market.c +++ b/src/gamecode/market.c @@ -17,7 +17,7 @@ without prior permission by the authors of Eressea. #include #include -#include +#include #include #include diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 72e5e4ab1..03772de43 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -77,7 +77,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/gamecode/spy.c b/src/gamecode/spy.c index 10b83f31a..76b0360b5 100644 --- a/src/gamecode/spy.c +++ b/src/gamecode/spy.c @@ -43,7 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/gamecode/xmlreport.c b/src/gamecode/xmlreport.c index 33a740a76..72025e98a 100644 --- a/src/gamecode/xmlreport.c +++ b/src/gamecode/xmlreport.c @@ -58,7 +58,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index ddb92fcf4..ede4b0dfd 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -34,7 +34,7 @@ without prior permission by the authors of Eressea. #include #include #include -#include +#include #include #include diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 36abba1b9..ab7a52db7 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -61,7 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/kernel/building.c b/src/kernel/building.c index 0edb9a6bc..0b695622d 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -40,7 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/config.c b/src/kernel/config.c index 23124860b..23b568579 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -62,7 +62,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 98ac0234b..ec3c31b67 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 016b96212..4a7403e69 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -284,7 +284,7 @@ attrib_type at_curse = { /* Spruch identifizieren */ #include -#include +#include static quicklist *cursetypes[256]; diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 2ef21717c..956cc0626 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "spellbook.h" /* util includes */ -#include +#include #include #include diff --git a/src/kernel/equipment_test.c b/src/kernel/equipment_test.c index 071cf3521..a526c5abc 100644 --- a/src/kernel/equipment_test.c +++ b/src/kernel/equipment_test.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 6c33d9dd7..ff011bc38 100644 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -41,7 +41,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/magic.c b/src/kernel/magic.c index f41c8eaa7..a0bbef2a0 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -57,7 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/magic_test.c b/src/kernel/magic_test.c index bca8f6198..8a4a1ef69 100644 --- a/src/kernel/magic_test.c +++ b/src/kernel/magic_test.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 97cea3b98..c9adf3251 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#include +#include #include "pathfinder.h" #include "region.h" diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 8fb83abd7..e6ae19581 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -53,7 +53,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include diff --git a/src/kernel/save.c b/src/kernel/save.c index ccc28c895..cf7724a96 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -65,7 +65,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 6c008dfd6..141bd4ba9 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -36,7 +36,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include #include #include diff --git a/src/kernel/spell.c b/src/kernel/spell.c index 85cf35c40..41966ef5d 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -26,7 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#include /* libc includes */ #include diff --git a/src/kernel/spell_test.c b/src/kernel/spell_test.c index e8bbeb328..90ab1cdf0 100644 --- a/src/kernel/spell_test.c +++ b/src/kernel/spell_test.c @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 7093fca84..4f2b736b6 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include "spellbook.h" diff --git a/src/kernel/spellbook_test.c b/src/kernel/spellbook_test.c index 6196d901c..277952e0c 100644 --- a/src/kernel/spellbook_test.c +++ b/src/kernel/spellbook_test.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index d21ac4658..18ae8e51a 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/modules/wormhole.c b/src/modules/wormhole.c index e606eab2f..d018c358f 100644 --- a/src/modules/wormhole.c +++ b/src/modules/wormhole.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include /* libc includes */ diff --git a/src/tests.c b/src/tests.c index b41bdaaf3..7c24bfb0f 100644 --- a/src/tests.c +++ b/src/tests.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -51,7 +50,6 @@ int RunAllTests(void) /* util */ CuSuiteAddSuite(suite, get_base36_suite()); CuSuiteAddSuite(suite, get_bsdstring_suite()); - CuSuiteAddSuite(suite, get_quicklist_suite()); CuSuiteAddSuite(suite, get_functions_suite()); CuSuiteAddSuite(suite, get_umlaut_suite()); /* kernel */ diff --git a/src/util/quicklist.c b/src/util/quicklist.c deleted file mode 100644 index 0e8842ccb..000000000 --- a/src/util/quicklist.c +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright (c) 2010-2011, Enno Rehling - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include "quicklist.h" -#include -#include -#include - -#define QL_MAXSIZE 14 /* max. number of elements unrolled into one node */ -#define QL_LIMIT 7 /* this many or fewer number in a node => attempt merge */ - -/* The total size of this struct is 64 bytes on a 32-bit system with - * normal alignment. YMMV, so on a 64-bit system, twiddle the - * constants above */ -struct quicklist { - struct quicklist *next; - int num_elements; - void *elements[QL_MAXSIZE]; -}; - -void *ql_get(const quicklist * ql, int index) -{ - return (ql - && index < ql->num_elements) ? ql->elements[index] : ql_get(ql->next, - index - ql->num_elements); -} - -void *ql_replace(quicklist * ql, int index, void *data) -{ - if (ql && index < ql->num_elements) { - void *orig = ql->elements[index]; - ql->elements[index] = data; - return orig; - } else { - return ql_replace(ql->next, index - ql->num_elements, data); - } -} - -int ql_length(const quicklist * ql) -{ - return ql ? ql->num_elements + ql_length(ql->next) : 0; -} - -int ql_empty(const quicklist * ql) -{ - return !ql; -} - -void ql_push(quicklist ** qlp, void *data) -{ - quicklist *ql = 0; - while (*qlp && ((*qlp)->next || (*qlp)->num_elements == QL_MAXSIZE)) { - qlp = &(*qlp)->next; - } - if (!*qlp) { - ql = (quicklist *) malloc(sizeof(quicklist)); - ql->num_elements = 0; - ql->next = 0; - *qlp = ql; - } else { - ql = *qlp; - } - ql->elements[ql->num_elements++] = data; -} - -int ql_delete(quicklist ** qlp, int index) -{ - quicklist *ql = *qlp; - if (index < 0) - return EINVAL; - if (ql && index >= ql->num_elements) { - return ql_delete(&ql->next, index - ql->num_elements); - } else if (ql) { - if (index + 1 < ql->num_elements) { - memmove(ql->elements + index, ql->elements + index + 1, - (ql->num_elements - index - 1) * sizeof(void *)); - } - --ql->num_elements; - if (ql->num_elements == 0) { - *qlp = ql->next; - free(ql); - } else if (ql->next && ql->num_elements <= QL_LIMIT) { - quicklist *qn = ql->next; - if (ql->num_elements + qn->num_elements > QL_MAXSIZE) { - memcpy(ql->elements + ql->num_elements, qn->elements, sizeof(void *)); - --qn->num_elements; - ++ql->num_elements; - memmove(qn->elements, qn->elements + 1, - qn->num_elements * sizeof(void *)); - } else { - memcpy(ql->elements + ql->num_elements, qn->elements, - qn->num_elements * sizeof(void *)); - ql->num_elements += qn->num_elements; - ql->next = qn->next; - free(qn); - } - } - } - return 0; -} - -int ql_insert(quicklist ** qlp, int index, void *data) -{ - quicklist *ql = *qlp; - if (ql) { - if (index >= QL_MAXSIZE) { - return ql_insert(&ql->next, index - ql->num_elements, data); - } else if (ql->num_elements < QL_MAXSIZE) { - memmove(ql->elements + index + 1, ql->elements + index, - (ql->num_elements - index) * sizeof(void *)); - ql->elements[index] = data; - ++ql->num_elements; - } else { - quicklist *qn = (quicklist *) malloc(sizeof(quicklist)); - qn->next = ql->next; - ql->next = qn; - qn->num_elements = ql->num_elements-QL_LIMIT; - ql->num_elements = QL_LIMIT; - memcpy(qn->elements, ql->elements + ql->num_elements, - qn->num_elements * sizeof(void *)); - if (index <= ql->num_elements) { - return ql_insert(qlp, index, data); - } else { - return ql_insert(&ql->next, index - ql->num_elements, data); - } - } - } else if (index == 0) { - ql_push(qlp, data); - } else { - return EINVAL; - } - return 0; -} - -void ql_foreach(struct quicklist *ql, void (*cb) (void *)) -{ - for (; ql; ql = ql->next) { - int i; - for (i = 0; i != ql->num_elements; ++i) { - cb(ql->elements[i]); - } - } -} - -int ql_advance(struct quicklist **iterator, int *index, int stride) -{ - quicklist *ql = *iterator; - int i = *index; - if (!ql || i < 0 || stride < 0) { - return ERANGE; - } else if (i + stride < ql->num_elements) { - *index = i + stride; - return 0; - } else { - *index = i - ql->num_elements + stride; - *iterator = ql->next; - return ql_advance(iterator, index, 0); - } -} - -void ql_free(struct quicklist *ql) -{ - while (ql) { - quicklist * qn = ql; - ql = ql->next; - free(qn); - } -} - -int ql_set_remove(struct quicklist **qlp, void *data) -{ - int qi; - quicklist *ql = *qlp; - - if (!ql) - return 0; - - for (qi = 0; qi != ql->num_elements; ++qi) { - void *qd = ql_get(ql, qi); - if (qd == data) { - return ql_delete(qlp, qi) == 0; - } - } - return ql_set_remove(&ql->next, data); -} - -int ql_set_insert(struct quicklist **qlp, void *data) -{ - if (*qlp) { - quicklist *ql = *qlp; - if (ql->num_elements > 0 && ql->elements[ql->num_elements - 1] < data) { - if (ql->num_elements == QL_MAXSIZE || (ql->next - && ql->next->elements[0] <= data)) { - return ql_set_insert(&ql->next, data); - } else { - ql->elements[ql->num_elements++] = data; - } - return 0; - } else { - int i; - /* TODO: OPT | binary search */ - for (i = 0; i != ql->num_elements; ++i) { - if (data < ql->elements[i]) { - ql_insert(qlp, i, data); - return 0; - } - if (data == ql->elements[i]) { - return 1; - } - } - } - } - ql_push(qlp, data); - return 0; -} - -int ql_set_find(struct quicklist **qlp, int *qip, const void *data) -{ - quicklist *ql = *qlp; - int qi; - - while (ql && ql->elements[ql->num_elements - 1] < data) { - ql = ql->next; - } - - if (!ql) - return 0; - - /* TODO: OPT | binary search */ - for (qi = 0; qi != ql->num_elements; ++qi) { - if (ql->elements[qi] > data) { - return 0; - } - if (ql->elements[qi] == data) { - if (qip) { - *qip = qi; - *qlp = ql; - } - return 1; - } - } - return 0; -} diff --git a/src/util/quicklist.h b/src/util/quicklist.h deleted file mode 100644 index 01b918543..000000000 --- a/src/util/quicklist.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright (c) 2010-2011, Enno Rehling - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef _QUICKLIST_H -#define _QUICKLIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* see http://en.wikipedia.org/wiki/Unrolled_linked_list */ - typedef struct quicklist quicklist; - void *ql_get(const struct quicklist *ql, int index); - int ql_length(const struct quicklist *ql); - int ql_empty(const struct quicklist *ql); - void ql_push(struct quicklist **qlp, void *data); - int ql_delete(struct quicklist **qlp, int index); - int ql_insert(struct quicklist **qlp, int index, void *data); - void ql_foreach(struct quicklist *ql, void (*cb) (void *)); - int ql_advance(struct quicklist **iterator, int *index, int stride); - void ql_free(struct quicklist *ql); - void *ql_replace(struct quicklist *ql, int index, void *data); - -/* you can use it as a set (sorted pointers)*/ - int ql_set_insert(struct quicklist **qlp, void *data); - int ql_set_find(struct quicklist **qlp, int *qip, const void *data); - int ql_set_remove(struct quicklist **qlp, void *data); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/util/quicklist_test.c b/src/util/quicklist_test.c deleted file mode 100644 index 36c95e5a2..000000000 --- a/src/util/quicklist_test.c +++ /dev/null @@ -1,203 +0,0 @@ -#include -#include -#include -#include "quicklist.h" - -static const char *hello = "Hello World"; - -static void test_insert(CuTest * tc) -{ - struct quicklist *ql = NULL; - int i; - for (i = 0; i != 32; ++i) { - CuAssertIntEquals(tc, i, ql_length(ql)); - ql_insert(&ql, 0, (void *)i); - } - for (i = 0; i != 32; ++i) { - CuAssertIntEquals(tc, 31 - i, (int)ql_get(ql, i)); - } -} - -static void test_insert_delete_gives_null(CuTest * tc) -{ - struct quicklist *ql = NULL; - CuAssertIntEquals(tc, 1, ql_empty(ql)); - ql_push(&ql, (void *)42); - CuAssertIntEquals(tc, 0, ql_empty(ql)); - ql_delete(&ql, 0); - CuAssertPtrEquals(tc, 0, ql); -} - -static void test_replace(CuTest * tc) -{ - struct quicklist *ql = NULL; - int a; - ql_push(&ql, (void *)42); - a = (int)ql_replace(ql, 0, (void *)43); - CuAssertIntEquals(tc, 42, a); - CuAssertIntEquals(tc, 43, (int)ql_get(ql, 0)); -} - -static void test_set_insert(CuTest * tc) -{ - struct quicklist *ql = NULL; - int a, qi; - a = ql_set_insert(&ql, (void *)42); - CuAssertIntEquals(tc, 1, ql_length(ql)); - CuAssertIntEquals(tc, 0, a); - a = ql_set_insert(&ql, (void *)43); - CuAssertIntEquals(tc, 2, ql_length(ql)); - CuAssertIntEquals(tc, 0, a); - a = ql_set_insert(&ql, (void *)42); - CuAssertIntEquals(tc, 2, ql_length(ql)); - CuAssertIntEquals(tc, 1, a); - a = ql_set_insert(&ql, (void *)41); - CuAssertIntEquals(tc, 0, a); - CuAssertIntEquals(tc, 3, ql_length(ql)); - CuAssertIntEquals(tc, 41, (int)ql_get(ql, 0)); - CuAssertIntEquals(tc, 42, (int)ql_get(ql, 1)); - CuAssertIntEquals(tc, 43, (int)ql_get(ql, 2)); - - a = ql_set_find(&ql, &qi, (void *)49); - CuAssertIntEquals(tc, 0, a); - a = ql_set_find(&ql, &qi, (void *)42); - CuAssertIntEquals(tc, 1, a); - CuAssertIntEquals(tc, 42, (int)ql_get(ql, qi)); -} - -static void test_set_remove(CuTest * tc) -{ - struct quicklist *ql = NULL, *q2; - int a; - - ql_set_insert(&ql, (void *)41); - ql_set_insert(&ql, (void *)42); - ql_set_insert(&ql, (void *)43); - - q2 = ql; - - a = ql_set_remove(&ql, (void *)42); - CuAssertPtrEquals(tc, q2, ql); - CuAssertIntEquals(tc, 1, a); - CuAssertIntEquals(tc, 41, (int)ql_get(ql, 0)); - CuAssertIntEquals(tc, 43, (int)ql_get(ql, 1)); - CuAssertIntEquals(tc, 2, ql_length(ql)); - - a = ql_set_remove(&ql, (void *)42); - CuAssertPtrEquals(tc, q2, ql); - CuAssertIntEquals(tc, 0, a); - - ql_set_remove(&ql, (void *)41); - ql_set_remove(&ql, (void *)43); - CuAssertPtrEquals(tc, 0, ql); -} - -static void test_set_find(CuTest * tc) -{ - struct quicklist *ql = NULL, *q2; - int a, qi; - - for (a = 0; a != 32; ++a) { - ql_set_insert(&ql, (void *)a); - } - - q2 = ql; - a = ql_set_find(&q2, 0, (void *)31); - CuAssertIntEquals(tc, 1, a); - CuAssertPtrEquals(tc, ql, q2); - - q2 = ql; - a = ql_set_find(&ql, &qi, (void *)0); - CuAssertIntEquals(tc, 1, a); - CuAssertIntEquals(tc, 0, qi); - CuAssertPtrEquals(tc, ql, q2); - - q2 = ql; - a = ql_set_find(&ql, &qi, (void *)31); - CuAssertIntEquals(tc, 1, a); - CuAssertIntEquals(tc, 31, (int)ql_get(ql, qi)); - CuAssertTrue(tc, ql != q2); -} - -static void test_advance(CuTest * tc) -{ - struct quicklist *ql = NULL, *qli; - int i, n = 31; - for (i = 0; i != 32; ++i) { - ql_insert(&ql, 0, (void *)i); - } - for (i = 0, qli = ql; qli; ql_advance(&qli, &i, 1), n--) { - int g = (int)ql_get(qli, i); - CuAssertIntEquals(tc, n, g); - } -} - -static void test_push(CuTest * tc) -{ - struct quicklist *ql = NULL; - CuAssertIntEquals(tc, 0, ql_length(ql)); - ql_push(&ql, (void *)hello); - CuAssertIntEquals(tc, 1, ql_length(ql)); - CuAssertStrEquals(tc, "Hello World", (const char *)ql_get(ql, 0)); - ql_delete(&ql, 0); - CuAssertPtrEquals(tc, 0, ql); -} - -static void test_delete_edgecases(CuTest * tc) -{ - struct quicklist *ql = NULL; - ql_delete(&ql, 0); - CuAssertPtrEquals(tc, 0, ql); - ql_push(&ql, (void *)hello); - ql_delete(&ql, -1); - ql_delete(&ql, 32); - CuAssertIntEquals(tc, 1, ql_length(ql)); -} - -static void test_insert_many(CuTest * tc) -{ - struct quicklist *ql = NULL; - int i; - for (i = 0; i != 32; ++i) { - ql_push(&ql, (void *)i); - } - for (i = 0; i != 32; ++i) { - CuAssertIntEquals(tc, 32 - i, ql_length(ql)); - CuAssertIntEquals(tc, i, (int)ql_get(ql, 0)); - CuAssertIntEquals(tc, 31, (int)ql_get(ql, ql_length(ql) - 1)); - ql_delete(&ql, 0); - } - CuAssertPtrEquals(tc, 0, ql); -} - -static void test_delete_rand(CuTest * tc) -{ - struct quicklist *ql = NULL; - int i; - for (i = 0; i != 32; ++i) { - ql_push(&ql, (void *)i); - } - CuAssertIntEquals(tc, 32, ql_length(ql)); - ql_delete(&ql, 0); - CuAssertIntEquals(tc, 1, (int)ql_get(ql, 0)); - CuAssertIntEquals(tc, 31, ql_length(ql)); - ql_delete(&ql, 30); - CuAssertIntEquals(tc, 30, ql_length(ql)); -} - -CuSuite *get_quicklist_suite(void) -{ - CuSuite *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_advance); - SUITE_ADD_TEST(suite, test_replace); - SUITE_ADD_TEST(suite, test_push); - SUITE_ADD_TEST(suite, test_insert); - SUITE_ADD_TEST(suite, test_set_remove); - SUITE_ADD_TEST(suite, test_set_find); - SUITE_ADD_TEST(suite, test_insert_delete_gives_null); - SUITE_ADD_TEST(suite, test_insert_many); - SUITE_ADD_TEST(suite, test_delete_rand); - SUITE_ADD_TEST(suite, test_delete_edgecases); - SUITE_ADD_TEST(suite, test_set_insert); - return suite; -}