]> git.kaiwu.me - klib.git/commitdiff
more tests
authorAttractive Chaos <attractor@live.co.uk>
Thu, 19 Dec 2019 18:52:42 +0000 (13:52 -0500)
committerAttractive Chaos <attractor@live.co.uk>
Thu, 19 Dec 2019 18:52:42 +0000 (13:52 -0500)
krmq.h
test/krmq_test.c

diff --git a/krmq.h b/krmq.h
index b2ba94455dbb1e883ac9826192f345b833f1d351..4f4ea75f885586c71d09ad953094c97efee5ebb5 100644 (file)
--- a/krmq.h
+++ b/krmq.h
@@ -127,7 +127,7 @@ int main(void) {
                        else if (cmp > 0) p = p->__head.p[1]; \
                        else break; \
                } \
-               for (i = 0; i < plen[0] && i < plen[1]; ++i) \
+               for (i = 0; i < plen[0] && i < plen[1]; ++i) /* find the LCA */ \
                        if (path[0][i] == path[1][i] && pcmp[0][i] <= 0 && pcmp[1][i] >= 0) \
                                break; \
                if (i == plen[0] || i == plen[1]) return 0; /* no elements in the closed interval */ \
index 8af20ca720394db0be2ccd26ac92235846516e44..69aff4c80b1c6a5698a21a932d8befff526971ab 100644 (file)
@@ -133,6 +133,12 @@ int main(void)
        check_rmq(root, 'A', 'Z');
        check_rmq(root, 'F', 'G');
        check_rmq(root, 'a', 'z');
+       for (i = 0; i < n; ++i) {
+               int lo, hi;
+               lo = (int)(drand48() * n);
+               hi = (int)(drand48() * n);
+               check_rmq(root, lo, hi);
+       }
 
        krmq_itr_first(my, root, &itr);
        do {