Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_
00036 #define OPENCV_FLANN_DYNAMIC_BITSET_H_
00037
00038 #ifndef FLANN_USE_BOOST
00039 # define FLANN_USE_BOOST 0
00040 #endif
00041
00042 #if FLANN_USE_BOOST
00043 #include <boost/dynamic_bitset.hpp>
00044 typedef boost::dynamic_bitset<> DynamicBitset;
00045 #else
00046
00047 #include <limits.h>
00048
00049 #include "dist.h"
00050
00051 namespace cvflann {
00052
00057 class DynamicBitset
00058 {
00059 public:
00062 DynamicBitset()
00063 {
00064 }
00065
00069 DynamicBitset(size_t sz)
00070 {
00071 resize(sz);
00072 reset();
00073 }
00074
00077 void clear()
00078 {
00079 std::fill(bitset_.begin(), bitset_.end(), 0);
00080 }
00081
00085 bool empty() const
00086 {
00087 return bitset_.empty();
00088 }
00089
00092 void reset()
00093 {
00094 std::fill(bitset_.begin(), bitset_.end(), 0);
00095 }
00096
00100 void reset(size_t index)
00101 {
00102 bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_));
00103 }
00104
00111 void reset_block(size_t index)
00112 {
00113 bitset_[index / cell_bit_size_] = 0;
00114 }
00115
00119 void resize(size_t sz)
00120 {
00121 size_ = sz;
00122 bitset_.resize(sz / cell_bit_size_ + 1);
00123 }
00124
00128 void set(size_t index)
00129 {
00130 bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
00131 }
00132
00135 size_t size() const
00136 {
00137 return size_;
00138 }
00139
00144 bool test(size_t index) const
00145 {
00146 return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0;
00147 }
00148
00149 private:
00150 std::vector<size_t> bitset_;
00151 size_t size_;
00152 static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t);
00153 };
00154
00155 }
00156
00157 #endif
00158
00159 #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_