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 OPENCV_FLANN_DYNAMIC_BITSET_H_
36 #define OPENCV_FLANN_DYNAMIC_BITSET_H_
37 
38 #ifndef FLANN_USE_BOOST
39 # define FLANN_USE_BOOST 0
40 #endif
41 //#define FLANN_USE_BOOST 1
42 #if FLANN_USE_BOOST
43 #include <boost/dynamic_bitset.hpp>
44 typedef boost::dynamic_bitset<> DynamicBitset;
45 #else
46 
47 #include <limits.h>
48 
49 #include "dist.h"
50 
51 namespace cvflann {
52 
58 {
59 public:
63  {
64  }
65 
69  DynamicBitset(size_t sz)
70  {
71  resize(sz);
72  reset();
73  }
74 
77  void clear()
78  {
79  std::fill(bitset_.begin(), bitset_.end(), 0);
80  }
81 
85  bool empty() const
86  {
87  return bitset_.empty();
88  }
89 
92  void reset()
93  {
94  std::fill(bitset_.begin(), bitset_.end(), 0);
95  }
96 
100  void reset(size_t index)
101  {
102  bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_));
103  }
104 
111  void reset_block(size_t index)
112  {
113  bitset_[index / cell_bit_size_] = 0;
114  }
115 
119  void resize(size_t sz)
120  {
121  size_ = sz;
122  bitset_.resize(sz / cell_bit_size_ + 1);
123  }
124 
128  void set(size_t index)
129  {
130  bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
131  }
132 
135  size_t size() const
136  {
137  return size_;
138  }
139 
144  bool test(size_t index) const
145  {
146  return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0;
147  }
148 
149 private:
150  std::vector<size_t> bitset_;
151  size_t size_;
152  static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t);
153 };
154 
155 } // namespace cvflann
156 
157 #endif
158 
159 #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_
size_t size() const
Definition: dynamic_bitset.h:135
GLuint index
Definition: core_c.h:986
void set(size_t index)
Definition: dynamic_bitset.h:128
boost::dynamic_bitset DynamicBitset
Definition: dynamic_bitset.h:44
void clear()
Definition: dynamic_bitset.h:77
bool empty() const
checks if the bitset is empty
Definition: dynamic_bitset.h:85
void resize(size_t sz)
Definition: dynamic_bitset.h:119
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:111
DynamicBitset(size_t sz)
Definition: dynamic_bitset.h:69
DynamicBitset()
Definition: dynamic_bitset.h:62
Definition: dynamic_bitset.h:57
void reset(size_t index)
set one bit to 0
Definition: dynamic_bitset.h:100
bool test(size_t index) const
Definition: dynamic_bitset.h:144
void reset()
Definition: dynamic_bitset.h:92