tdb2: change to using a hash tree.
[ccan] / ccan / tdb2 / test / run-001-fls.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tap/tap.h>
7
8 static unsigned int dumb_fls(uint64_t num)
9 {
10         int i;
11
12         for (i = 63; i >= 0; i--) {
13                 if (num & (1ULL << i))
14                         break;
15         }
16         return i + 1;
17 }
18
19 int main(int argc, char *argv[])
20 {
21         unsigned int i, j;
22
23         plan_tests(64 * 64 + 2);
24
25         ok1(fls64(0) == 0);
26         ok1(dumb_fls(0) == 0);
27
28         for (i = 0; i < 64; i++) {
29                 for (j = 0; j < 64; j++) {
30                         uint64_t val = (1ULL << i) | (1ULL << j);
31                         ok(fls64(val) == dumb_fls(val),
32                            "%llu -> %u should be %u", (long long)val,
33                            fls64(val), dumb_fls(val));
34                 }
35         }
36         return exit_status();
37 }