1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3
// test the sub block index function
6
COPYING CONDITIONS NOTICE:
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of version 2 of the GNU General Public License as
10
published by the Free Software Foundation, and provided that the
11
following conditions are met:
13
* Redistributions of source code must retain this COPYING
14
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
15
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
16
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
19
* Redistributions in binary form must reproduce this COPYING
20
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
21
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
22
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
23
GRANT (below) in the documentation and/or other materials
24
provided with the distribution.
26
You should have received a copy of the GNU General Public License
27
along with this program; if not, write to the Free Software
28
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33
TokuDB, Tokutek Fractal Tree Indexing Library.
34
Copyright (C) 2007-2013 Tokutek, Inc.
38
This program is distributed in the hope that it will be useful, but
39
WITHOUT ANY WARRANTY; without even the implied warranty of
40
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41
General Public License for more details.
43
UNIVERSITY PATENT NOTICE:
45
The technology is licensed by the Massachusetts Institute of
46
Technology, Rutgers State University of New Jersey, and the Research
47
Foundation of State University of New York at Stony Brook under
48
United States of America Serial No. 11/760379 and to the patents
49
and/or patent applications resulting from it.
51
PATENT MARKING NOTICE:
53
This software is covered by US Patent No. 8,185,551.
54
This software is covered by US Patent No. 8,489,638.
58
"THIS IMPLEMENTATION" means the copyrightable works distributed by
59
Tokutek as part of the Fractal Tree project.
61
"PATENT CLAIMS" means the claims of patents that are owned or
62
licensable by Tokutek, both currently or in the future; and that in
63
the absence of this license would be infringed by THIS
64
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
66
"PATENT CHALLENGE" shall mean a challenge to the validity,
67
patentability, enforceability and/or non-infringement of any of the
68
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
70
Tokutek hereby grants to you, for the term and geographical scope of
71
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
72
irrevocable (except as stated in this section) patent license to
73
make, have made, use, offer to sell, sell, import, transfer, and
74
otherwise run, modify, and propagate the contents of THIS
75
IMPLEMENTATION, where such license applies only to the PATENT
76
CLAIMS. This grant does not include claims that would be infringed
77
only as a consequence of further modifications of THIS
78
IMPLEMENTATION. If you or your agent or licensee institute or order
79
or agree to the institution of patent litigation against any entity
80
(including a cross-claim or counterclaim in a lawsuit) alleging that
81
THIS IMPLEMENTATION constitutes direct or contributory patent
82
infringement, or inducement of patent infringement, then any rights
83
granted to you under this License shall terminate as of the date
84
such litigation is filed. If you or your agent or exclusive
85
licensee institute or order or agree to the institution of a PATENT
86
CHALLENGE, then Tokutek may terminate any rights granted to you
90
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
92
#include <toku_portability.h>
98
#include "sub_block.h"
101
test_sub_block_index(void) {
103
printf("%s:%d\n", __FUNCTION__, __LINE__);
105
const int n_sub_blocks = max_sub_blocks;
106
struct sub_block sub_block[n_sub_blocks];
108
size_t max_offset = 0;
109
for (int i = 0 ; i < n_sub_blocks; i++) {
111
sub_block_init(&sub_block[i]);
112
sub_block[i].uncompressed_size = size;
116
int offset_to_sub_block[max_offset];
117
for (int i = 0; i < (int) max_offset; i++)
118
offset_to_sub_block[i] = -1;
120
size_t start_offset = 0;
121
for (int i = 0; i < n_sub_blocks; i++) {
122
size_t size = sub_block[i].uncompressed_size;
123
for (int j = 0; j < (int) (start_offset + size); j++) {
124
if (offset_to_sub_block[j] == -1)
125
offset_to_sub_block[j] = i;
127
start_offset += size;
131
for (size_t offset = 0; offset < max_offset; offset++) {
132
r = get_sub_block_index(n_sub_blocks, sub_block, offset);
134
printf("%s:%d %u %d\n", __FUNCTION__, __LINE__, (unsigned int) offset, r);
135
assert(0 <= r && r < n_sub_blocks);
136
assert(r == offset_to_sub_block[offset]);
139
r = get_sub_block_index(n_sub_blocks, sub_block, max_offset);
144
test_main (int argc, const char *argv[]) {
146
for (i=1; i<argc; i++) {
147
const char *arg = argv[i];
148
if (strcmp(arg, "-v") == 0)
151
test_sub_block_index();