123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_
- #define OPENCV_FLANN_DYNAMIC_BITSET_H_
- #ifndef FLANN_USE_BOOST
- # define FLANN_USE_BOOST 0
- #endif
- #if FLANN_USE_BOOST
- #include <boost/dynamic_bitset.hpp>
- typedef boost::dynamic_bitset<> DynamicBitset;
- #else
- #include <limits.h>
- #include "dist.h"
- namespace cvflann {
- class DynamicBitset
- {
- public:
-
- DynamicBitset()
- {
- }
-
- DynamicBitset(size_t sz)
- {
- resize(sz);
- reset();
- }
-
- void clear()
- {
- std::fill(bitset_.begin(), bitset_.end(), 0);
- }
-
- bool empty() const
- {
- return bitset_.empty();
- }
-
- void reset()
- {
- std::fill(bitset_.begin(), bitset_.end(), 0);
- }
-
- void reset(size_t index)
- {
- bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_));
- }
-
- void reset_block(size_t index)
- {
- bitset_[index / cell_bit_size_] = 0;
- }
-
- void resize(size_t sz)
- {
- size_ = sz;
- bitset_.resize(sz / cell_bit_size_ + 1);
- }
-
- void set(size_t index)
- {
- bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
- }
-
- size_t size() const
- {
- return size_;
- }
-
- bool test(size_t index) const
- {
- return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0;
- }
- private:
- std::vector<size_t> bitset_;
- size_t size_;
- static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t);
- };
- }
- #endif
- #endif
|