corelib
src
rtflann
util
dynamic_bitset.h
Go to the documentation of this file.
1
/***********************************************************************
2
* Software License Agreement (BSD License)
3
*
4
* Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5
* Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6
*
7
* THE BSD LICENSE
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
*
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
*************************************************************************/
30
31
/***********************************************************************
32
* Author: Vincent Rabaud
33
*************************************************************************/
34
35
#ifndef RTABMAP_FLANN_DYNAMIC_BITSET_H_
36
#define RTABMAP_FLANN_DYNAMIC_BITSET_H_
37
38
//#define FLANN_USE_BOOST 1
39
#if FLANN_USE_BOOST
40
#include <boost/dynamic_bitset.hpp>
41
typedef
boost::dynamic_bitset<> DynamicBitset;
42
#else
43
44
#include <limits.h>
45
46
namespace
rtflann
{
47
52
class
DynamicBitset
53
{
54
public
:
57
DynamicBitset
() :
size_
(0)
58
{
59
}
60
64
DynamicBitset
(
size_t
size
)
65
{
66
resize
(
size
);
67
reset
();
68
}
69
72
void
clear
()
73
{
74
std::fill(
bitset_
.begin(),
bitset_
.end(), 0);
75
}
76
80
bool
empty
()
const
81
{
82
return
bitset_
.empty();
83
}
84
87
void
reset
()
88
{
89
std::fill(
bitset_
.begin(),
bitset_
.end(), 0);
90
}
91
95
void
reset
(
size_t
index)
96
{
97
bitset_
[index /
cell_bit_size_
] &= ~(
size_t
(1) << (index %
cell_bit_size_
));
98
}
99
106
void
reset_block
(
size_t
index)
107
{
108
bitset_
[index /
cell_bit_size_
] = 0;
109
}
110
114
void
resize
(
size_t
size
)
115
{
116
size_
=
size
;
117
bitset_
.resize(
size
/
cell_bit_size_
+ 1);
118
}
119
123
void
set
(
size_t
index)
124
{
125
bitset_
[index /
cell_bit_size_
] |=
size_t
(1) << (index %
cell_bit_size_
);
126
}
127
130
size_t
size
()
const
131
{
132
return
size_
;
133
}
134
139
bool
test
(
size_t
index)
const
140
{
141
return
(
bitset_
[index /
cell_bit_size_
] & (
size_t
(1) << (index %
cell_bit_size_
))) != 0;
142
}
143
144
private
:
145
template
<
typename
Archive>
146
void
serialize
(Archive& ar)
147
{
148
ar &
size_
;
149
ar &
bitset_
;
150
}
151
friend
struct
serialization::access
;
152
153
private
:
154
std::vector<size_t>
bitset_
;
155
size_t
size_
;
156
static
const
unsigned
int
cell_bit_size_
= CHAR_BIT *
sizeof
(
size_t
);
157
};
158
159
}
// namespace flann
160
161
#endif
162
163
#endif // FLANN_DYNAMIC_BITSET_H_
rtflann::DynamicBitset::cell_bit_size_
static const unsigned int cell_bit_size_
Definition:
dynamic_bitset.h:216
rtflann::DynamicBitset::reset
void reset()
Definition:
dynamic_bitset.h:147
rtflann::DynamicBitset::empty
bool empty() const
checks if the bitset is empty
Definition:
dynamic_bitset.h:140
rtflann::DynamicBitset::serialize
void serialize(Archive &ar)
Definition:
dynamic_bitset.h:206
rtflann::DynamicBitset::clear
void clear()
Definition:
dynamic_bitset.h:132
rtflann::DynamicBitset::reset_block
void reset_block(size_t index)
sets a specific bit to 0, and more bits too This function is useful when resetting a given set of bit...
Definition:
dynamic_bitset.h:166
rtflann::DynamicBitset::bitset_
std::vector< size_t > bitset_
Definition:
dynamic_bitset.h:214
rtflann::serialization::access
Definition:
serialization.h:29
rtflann::DynamicBitset::test
bool test(size_t index) const
Definition:
dynamic_bitset.h:199
rtflann::DynamicBitset::resize
void resize(size_t size)
Definition:
dynamic_bitset.h:174
rtflann::DynamicBitset::size
size_t size() const
Definition:
dynamic_bitset.h:190
rtflann::DynamicBitset::size_
size_t size_
Definition:
dynamic_bitset.h:215
size_t
std::size_t size_t
rtflann::DynamicBitset::DynamicBitset
DynamicBitset()
Definition:
dynamic_bitset.h:117
rtflann::DynamicBitset::set
void set(size_t index)
Definition:
dynamic_bitset.h:183
rtflann
Definition:
all_indices.h:49
rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:09