X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fintmap%2Ftest%2Frun-order.c;h=d945a4a86f5a6e35e5a6e5ad3c29956a9935b3fa;hb=7aac849abf06ef469c2aad9a0dd6e3bb82ef1f96;hp=c44d2ba3b3bd02b50d3feb04b7e6a39a5ccf4f4f;hpb=d9e93014a999102aa1cc9979e041cd58e6aca724;p=ccan diff --git a/ccan/intmap/test/run-order.c b/ccan/intmap/test/run-order.c index c44d2ba3..d945a4a8 100644 --- a/ccan/intmap/test/run-order.c +++ b/ccan/intmap/test/run-order.c @@ -7,40 +7,100 @@ typedef UINTMAP(unsigned int *) umap; typedef SINTMAP(int *) smap; +static bool uint_iterate_check(intmap_index_t i, unsigned int *v, int64_t *prev) +{ + if ((int64_t)i <= *prev) + return false; + if (*v != i) + return false; + *prev = i; + return true; +} + static bool check_umap(const umap *map) { /* This is a larger type than unsigned, and allows negative */ - int64_t i, prev; + int64_t prev; + uint64_t i, last_idx; + unsigned int *v; + bool last = true; /* Must be in order, must contain value. */ prev = -1; - for (i = uintmap_first(map); i != -1ULL; i = uintmap_after(map, i)) { - if (i <= prev) + for (v = uintmap_first(map, &i); v; v = uintmap_after(map, &i)) { + if ((int64_t)i <= prev) return false; - if (*(unsigned int *)uintmap_get(map, i) != i) + if (*v != i) return false; prev = i; + last = (uintmap_last(map, &last_idx) == v); } + + if (!last) + return false; + + prev = INT_MAX; + for (v = uintmap_last(map, &i); v; v = uintmap_before(map, &i)) { + if ((int64_t)i >= prev) + return false; + if (*v != i) + return false; + prev = i; + last = (uintmap_first(map, &last_idx) == v); + } + + if (!last) + return false; + + prev = -1; + return uintmap_iterate(map, uint_iterate_check, &prev); +} + +static bool sint_iterate_check(sintmap_index_t i, int *v, int64_t *prev) +{ + if (i <= *prev) + return false; + if (*v != i) + return false; + *prev = i; return true; } static bool check_smap(const smap *map) { /* This is a larger type than int, and allows negative */ - int64_t i, prev; + int64_t prev, i, last_idx; + int *v; + bool last = true; /* Must be in order, must contain value. */ prev = -0x80000001ULL; - for (i = sintmap_first(map); - i != 0x7FFFFFFFFFFFFFFFLL; - i = sintmap_after(map, i)) { + for (v = sintmap_first(map, &i); v; v = sintmap_after(map, &i)) { if (i <= prev) return false; - if (*(int *)sintmap_get(map, i) != i) + if (*v != i) return false; + last = (sintmap_last(map, &last_idx) == v); prev = i; } - return true; + + if (!last) + return false; + + prev = 0x80000001ULL; + for (v = sintmap_last(map, &i); v; v = sintmap_before(map, &i)) { + if (i >= prev) + return false; + if (*v != i) + return false; + prev = i; + last = (sintmap_first(map, &last_idx) == v); + } + if (!last) + return false; + + prev = -1; + return sintmap_iterate(map, sint_iterate_check, &prev); } int main(void)