test_00042_find_limited.c 3.86 KB
Newer Older
1 2
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
Yoni Fogel's avatar
Yoni Fogel committed
3 4 5 6
/* We are going to test whether we can insert and delete. */

#include "test.h"

Yoni Fogel's avatar
Yoni Fogel committed
7
int nums[200];
Yoni Fogel's avatar
Yoni Fogel committed
8 9 10 11 12 13
char letters[2] = {'A','B'};

toku_range_tree *tree;
toku_range* buf;
unsigned buflen;

14
#include "run.h"
Yoni Fogel's avatar
Yoni Fogel committed
15

16
static void
17
tests (bool allow_overlaps) {
Yoni Fogel's avatar
Yoni Fogel committed
18
    toku_interval query;
Yoni Fogel's avatar
Yoni Fogel committed
19 20 21 22 23 24 25 26 27
    toku_range insert;
    /*
        Limited/Unlimited Queries

        Limit of k does not produce all, but limit of 0 does.         Single point overlaps
    */

    /* Tree: {|0-1|,|2-3|,|4-5|,|6-7|,|8-9|}, query of |2-7|, limit 2 finds 2,
        limit 3 finds 3, limit 4 finds 3, limit 0 finds 3 */
28
    setup_tree(allow_overlaps, true, 0, 1, 0);
Yoni Fogel's avatar
Yoni Fogel committed
29 30 31 32 33
    runinsert(0, init_range(&insert, 2, 3, 0)); 
    runinsert(0, init_range(&insert, 4, 5, 0)); 
    runinsert(0, init_range(&insert, 6, 7, 0)); 
    runinsert(0, init_range(&insert, 8, 9, 0));
    
Yoni Fogel's avatar
Yoni Fogel committed
34 35 36 37 38
    runlimitsearch(init_query(&query, 2, 7), 0, 3);
    runlimitsearch(init_query(&query, 2, 7), 1, 1);
    runlimitsearch(init_query(&query, 2, 7), 2, 2);
    runlimitsearch(init_query(&query, 2, 7), 3, 3);
    runlimitsearch(init_query(&query, 2, 7), 4, 3);
Yoni Fogel's avatar
Yoni Fogel committed
39
    close_tree();
Yoni Fogel's avatar
Yoni Fogel committed
40 41
    
    /* Tree is empty (return none) */
42
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
43
    runlimitsearch(init_query(&query, 0, 0), 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
44 45 46
    close_tree();
    
    /* Tree contains only elements to the left. */
47
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
48 49
    runinsert(0, init_range(&insert, 1, 2, 0));
    runinsert(0, init_range(&insert, 3, 4, 0));
Yoni Fogel's avatar
Yoni Fogel committed
50
    runlimitsearch(init_query(&query, 8, 30), 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
51 52 53
    close_tree();
    
    /* Tree contains only elements to the right. */
54
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
55 56
    runinsert(0, init_range(&insert, 10, 20, 0));
    runinsert(0, init_range(&insert, 30, 40, 0));
Yoni Fogel's avatar
Yoni Fogel committed
57
    runlimitsearch(init_query(&query, 5, 7), 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
58 59 60
    close_tree();

    /* Tree contains only elements to the left and to the right. */
61
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
62 63 64 65
    runinsert(0, init_range(&insert, 10, 20, 0));
    runinsert(0, init_range(&insert, 30, 40, 0));
    runinsert(0, init_range(&insert, 70, 80, 0));
    runinsert(0, init_range(&insert, 90, 100, 0));
Yoni Fogel's avatar
Yoni Fogel committed
66
    runlimitsearch(init_query(&query, 60, 65), 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
67 68 69
    close_tree();
    
    /* Tree contains overlaps and elements to the left. */
70
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
71 72 73 74
    runinsert(0, init_range(&insert, 10, 20, 0));
    runinsert(0, init_range(&insert, 30, 40, 0));
    runinsert(0, init_range(&insert, 60, 80, 0));
    runinsert(0, init_range(&insert, 90, 100, 0));
Yoni Fogel's avatar
Yoni Fogel committed
75
    runlimitsearch(init_query(&query, 70, 95), 0, 2);
Yoni Fogel's avatar
Yoni Fogel committed
76 77 78
    close_tree();

    /* Tree contains overlaps and elements to the right. */
79
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
80 81 82 83
    runinsert(0, init_range(&insert, 110, 120, 0));
    runinsert(0, init_range(&insert, 130, 140, 0));
    runinsert(0, init_range(&insert, 60, 80, 0));
    runinsert(0, init_range(&insert, 90, 100, 0));
Yoni Fogel's avatar
Yoni Fogel committed
84
    runlimitsearch(init_query(&query, 70, 95), 0, 2);
Yoni Fogel's avatar
Yoni Fogel committed
85 86 87
    close_tree();

    /* Tree contains overlaps and elements to the left and to the right. */
88
    setup_tree(allow_overlaps, false, 0, 0, 0);
Yoni Fogel's avatar
Yoni Fogel committed
89 90 91 92 93 94
    runinsert(0, init_range(&insert, 10, 20, 0));
    runinsert(0, init_range(&insert, 30, 40, 0));
    runinsert(0, init_range(&insert, 110, 120, 0));
    runinsert(0, init_range(&insert, 130, 140, 0));
    runinsert(0, init_range(&insert, 60, 80, 0));
    runinsert(0, init_range(&insert, 90, 100, 0));
Yoni Fogel's avatar
Yoni Fogel committed
95
    runlimitsearch(init_query(&query, 70, 95), 0, 2);
Yoni Fogel's avatar
Yoni Fogel committed
96
    close_tree();
Yoni Fogel's avatar
Yoni Fogel committed
97 98 99
}

int main(int argc, const char *argv[]) {
Yoni Fogel's avatar
Yoni Fogel committed
100 101 102
    parse_args(argc, argv);

    unsigned i;
Yoni Fogel's avatar
Yoni Fogel committed
103 104 105
    for (i = 0; i < sizeof(nums) / sizeof(nums[0]); i++) nums[i] = i; 
    buflen = 2;
    buf = (toku_range*)toku_malloc(2 * sizeof(toku_range));
106
    tests(false);
Yoni Fogel's avatar
Yoni Fogel committed
107
#ifndef TOKU_RT_NOOVERLAPS
108
    tests(true);
Yoni Fogel's avatar
Yoni Fogel committed
109
#endif
Yoni Fogel's avatar
Yoni Fogel committed
110 111 112 113 114
    tree = NULL;
    toku_free(buf);
    buf = NULL;
    return 0;
}