1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
5
COPYING CONDITIONS NOTICE:
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of version 2 of the GNU General Public License as
9
published by the Free Software Foundation, and provided that the
10
following conditions are met:
12
* Redistributions of source code must retain this COPYING
13
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
14
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
15
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
18
* Redistributions in binary form must reproduce this COPYING
19
CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
20
DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
21
PATENT MARKING NOTICE (below), and the PATENT RIGHTS
22
GRANT (below) in the documentation and/or other materials
23
provided with the distribution.
25
You should have received a copy of the GNU General Public License
26
along with this program; if not, write to the Free Software
27
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32
TokuDB, Tokutek Fractal Tree Indexing Library.
33
Copyright (C) 2007-2013 Tokutek, Inc.
37
This program is distributed in the hope that it will be useful, but
38
WITHOUT ANY WARRANTY; without even the implied warranty of
39
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40
General Public License for more details.
42
UNIVERSITY PATENT NOTICE:
44
The technology is licensed by the Massachusetts Institute of
45
Technology, Rutgers State University of New Jersey, and the Research
46
Foundation of State University of New York at Stony Brook under
47
United States of America Serial No. 11/760379 and to the patents
48
and/or patent applications resulting from it.
50
PATENT MARKING NOTICE:
52
This software is covered by US Patent No. 8,185,551.
53
This software is covered by US Patent No. 8,489,638.
57
"THIS IMPLEMENTATION" means the copyrightable works distributed by
58
Tokutek as part of the Fractal Tree project.
60
"PATENT CLAIMS" means the claims of patents that are owned or
61
licensable by Tokutek, both currently or in the future; and that in
62
the absence of this license would be infringed by THIS
63
IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
65
"PATENT CHALLENGE" shall mean a challenge to the validity,
66
patentability, enforceability and/or non-infringement of any of the
67
PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
69
Tokutek hereby grants to you, for the term and geographical scope of
70
the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
71
irrevocable (except as stated in this section) patent license to
72
make, have made, use, offer to sell, sell, import, transfer, and
73
otherwise run, modify, and propagate the contents of THIS
74
IMPLEMENTATION, where such license applies only to the PATENT
75
CLAIMS. This grant does not include claims that would be infringed
76
only as a consequence of further modifications of THIS
77
IMPLEMENTATION. If you or your agent or licensee institute or order
78
or agree to the institution of patent litigation against any entity
79
(including a cross-claim or counterclaim in a lawsuit) alleging that
80
THIS IMPLEMENTATION constitutes direct or contributory patent
81
infringement, or inducement of patent infringement, then any rights
82
granted to you under this License shall terminate as of the date
83
such litigation is filed. If you or your agent or exclusive
84
licensee institute or order or agree to the institution of a PATENT
85
CHALLENGE, then Tokutek may terminate any rights granted to you
89
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
90
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
95
#include <tokudb_vlq.h>
98
template size_t vlq_encode_ui(uint32_t n, void *p, size_t s);
99
template size_t vlq_decode_ui(uint32_t *np, void *p, size_t s);
100
template size_t vlq_encode_ui(uint64_t n, void *p, size_t s);
101
template size_t vlq_decode_ui(uint64_t *np, void *p, size_t s);
104
static void test_vlq_uint32_error(void) {
109
out_s = tokudb::vlq_encode_ui<uint32_t>(128, b, 0);
111
out_s = tokudb::vlq_encode_ui<uint32_t>(128, b, 1);
113
out_s = tokudb::vlq_encode_ui<uint32_t>(128, b, 2);
115
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 0);
117
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 1);
119
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 2);
120
assert(in_s == 2 && n == 128);
123
static void test_vlq_uint32(void) {
129
for (uint32_t v = 0; v < (1<<7); v++) {
130
out_s = tokudb::vlq_encode_ui<uint32_t>(v, b, sizeof b);
132
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
133
assert(in_s == 1 && n == v);
136
printf("%u\n", 1<<7);
137
for (uint32_t v = (1<<7); v < (1<<14); v++) {
138
out_s = tokudb::vlq_encode_ui<uint32_t>(v, b, sizeof b);
140
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
141
assert(in_s == 2 && n == v);
144
printf("%u\n", 1<<14);
145
for (uint32_t v = (1<<14); v < (1<<21); v++) {
146
out_s = tokudb::vlq_encode_ui<uint32_t>(v, b, sizeof b);
148
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
149
assert(in_s == 3 && n == v);
152
printf("%u\n", 1<<21);
153
for (uint32_t v = (1<<21); v < (1<<28); v++) {
154
out_s = tokudb::vlq_encode_ui<uint32_t>(v, b, sizeof b);
156
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
157
assert(in_s == 4 && n == v);
160
printf("%u\n", 1<<28);
161
for (uint32_t v = (1<<28); v != 0; v++) {
162
out_s = tokudb::vlq_encode_ui<uint32_t>(v, b, sizeof b);
164
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
165
assert(in_s == 5 && n == v);
169
static void test_vlq_uint64(void) {
175
for (uint64_t v = 0; v < (1<<7); v++) {
176
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
178
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
179
assert(in_s == 1 && n == v);
182
printf("%u\n", 1<<7);
183
for (uint64_t v = (1<<7); v < (1<<14); v++) {
184
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
186
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
187
assert(in_s == 2 && n == v);
190
printf("%u\n", 1<<14);
191
for (uint64_t v = (1<<14); v < (1<<21); v++) {
192
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
194
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
195
assert(in_s == 3 && n == v);
198
printf("%u\n", 1<<21);
199
for (uint64_t v = (1<<21); v < (1<<28); v++) {
200
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
202
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
203
assert(in_s == 4 && n == v);
206
printf("%u\n", 1<<28);
207
for (uint64_t v = (1<<28); v < (1ULL<<35); v++) {
208
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
210
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
211
assert(in_s == 5 && n == v);
215
static void test_80000000(void) {
219
uint64_t v = 0x80000000;
220
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
222
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
223
assert(in_s == 5 && n == v);
226
static void test_100000000(void) {
230
uint64_t v = 0x100000000;
231
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
233
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
234
assert(in_s == 5 && n == v);
238
if (1) test_vlq_uint32_error();
239
if (1) test_80000000();
240
if (1) test_100000000();
241
if (1) test_vlq_uint32();
242
if (1) test_vlq_uint64();