MySQL 5.6.14 Source Code Document
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SparseBitmask.cpp
1
/*
2
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; version 2 of the License.
7
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16
*/
17
18
#include <util/SparseBitmask.hpp>
19
20
#ifdef TEST_SPARSEBITMASK
21
#include <util/NdbTap.hpp>
22
23
#include "parse_mask.hpp"
24
25
TAPTEST(
SparseBitmask
)
26
{
27
SparseBitmask
b;
28
OK(b.isclear());
29
for
(
unsigned
i
= 0;
i
< 100;
i
++)
30
{
31
if
(
i
> 60)
32
continue
;
33
switch
(
i
)
34
{
35
case
2:
case
3:
case
5:
case
7:
case
11:
case
13:
case
17:
case
19:
case
23:
36
case
29:
case
31:
case
37:
case
41:
case
43:
37
break
;
38
default
:
39
b.set(
i
);
40
}
41
}
42
43
unsigned
found = 0;
44
for
(
unsigned
i
= 0;
i
< 100;
i
++)
45
{
46
if
(b.get(
i
))
47
found++;
48
}
49
OK(found == b.count());
50
OK(found == 47);
51
52
// Set already set bit again
53
b.set(6);
54
OK(found == b.count());
55
56
/*
57
parse_mask
58
*/
59
SparseBitmask
mask(256);
60
OK(parse_mask(
"1,2,5-7"
, mask) == 5);
61
62
// Check all specified bits set
63
OK(mask.get(1));
64
OK(mask.get(2));
65
OK(mask.get(5));
66
OK(mask.get(6));
67
OK(mask.get(7));
68
69
// Check some random bits not set
70
OK(!mask.get(0));
71
OK(!mask.get(4));
72
OK(!mask.get(3));
73
OK(!mask.get(8));
74
OK(!mask.get(22));
75
76
// Parse some more...
77
OK(parse_mask(
"1-256"
, mask));
78
79
// Parse invalid spec(s)
80
OK(parse_mask(
"xx"
, mask) == -1);
81
OK(parse_mask(
"5-"
, mask) == -1);
82
OK(parse_mask(
"-5"
, mask) == -1);
83
OK(parse_mask(
"1,-5"
, mask) == -1);
84
85
// Parse too large spec
86
OK(parse_mask(
"257"
, mask) == -2);
87
OK(parse_mask(
"1-256,257"
, mask) == -2);
88
89
90
return
1;
// OK
91
}
92
93
#endif
storage
ndb
src
common
util
SparseBitmask.cpp
Generated on Sat Nov 9 2013 01:27:04 for MySQL 5.6.14 Source Code Document by
1.8.1.2