github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/flann/dynamic_bitset.h (about)

     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  //! @cond IGNORED
    39  
    40  #ifndef FLANN_USE_BOOST
    41  #  define FLANN_USE_BOOST 0
    42  #endif
    43  //#define FLANN_USE_BOOST 1
    44  #if FLANN_USE_BOOST
    45  #include <boost/dynamic_bitset.hpp>
    46  typedef boost::dynamic_bitset<> DynamicBitset;
    47  #else
    48  
    49  #include <limits.h>
    50  
    51  #include "dist.h"
    52  
    53  namespace cvflann {
    54  
    55  /** Class re-implementing the boost version of it
    56   * This helps not depending on boost, it also does not do the bound checks
    57   * and has a way to reset a block for speed
    58   */
    59  class DynamicBitset
    60  {
    61  public:
    62      /** default constructor
    63       */
    64      DynamicBitset() : size_(0)
    65      {
    66      }
    67  
    68      /** only constructor we use in our code
    69       * @param sz the size of the bitset (in bits)
    70       */
    71      DynamicBitset(size_t sz)
    72      {
    73          resize(sz);
    74          reset();
    75      }
    76  
    77      /** Sets all the bits to 0
    78       */
    79      void clear()
    80      {
    81          std::fill(bitset_.begin(), bitset_.end(), 0);
    82      }
    83  
    84      /** @brief checks if the bitset is empty
    85       * @return true if the bitset is empty
    86       */
    87      bool empty() const
    88      {
    89          return bitset_.empty();
    90      }
    91  
    92      /** set all the bits to 0
    93       */
    94      void reset()
    95      {
    96          std::fill(bitset_.begin(), bitset_.end(), 0);
    97      }
    98  
    99      /** @brief set one bit to 0
   100       * @param index
   101       */
   102      void reset(size_t index)
   103      {
   104          bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_));
   105      }
   106  
   107      /** @brief sets a specific bit to 0, and more bits too
   108       * This function is useful when resetting a given set of bits so that the
   109       * whole bitset ends up being 0: if that's the case, we don't care about setting
   110       * other bits to 0
   111       * @param index
   112       */
   113      void reset_block(size_t index)
   114      {
   115          bitset_[index / cell_bit_size_] = 0;
   116      }
   117  
   118      /** resize the bitset so that it contains at least sz bits
   119       * @param sz
   120       */
   121      void resize(size_t sz)
   122      {
   123          size_ = sz;
   124          bitset_.resize(sz / cell_bit_size_ + 1);
   125      }
   126  
   127      /** set a bit to true
   128       * @param index the index of the bit to set to 1
   129       */
   130      void set(size_t index)
   131      {
   132          bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
   133      }
   134  
   135      /** gives the number of contained bits
   136       */
   137      size_t size() const
   138      {
   139          return size_;
   140      }
   141  
   142      /** check if a bit is set
   143       * @param index the index of the bit to check
   144       * @return true if the bit is set
   145       */
   146      bool test(size_t index) const
   147      {
   148          return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0;
   149      }
   150  
   151  private:
   152      std::vector<size_t> bitset_;
   153      size_t size_;
   154      static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t);
   155  };
   156  
   157  } // namespace cvflann
   158  
   159  #endif
   160  
   161  //! @endcond
   162  
   163  #endif // OPENCV_FLANN_DYNAMIC_BITSET_H_