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 
53 {
54 public:
58  {
59  }
60 
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_
bool empty() const
checks if the bitset is empty
DynamicBitset(size_t size)
static const unsigned int cell_bit_size_
void reset(size_t index)
set one bit to 0
bool test(size_t index) const
void serialize(Archive &ar)
void resize(size_t size)
std::vector< size_t > bitset_
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...


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:28