Mercurial > foo_out_sdl
comparison foosdk/sdk/pfc/bit_array_impl_part2.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 #include "avltree.h" | |
| 3 #include "bsearch_inline.h" | |
| 4 #include "array.h" | |
| 5 | |
| 6 namespace pfc { | |
| 7 //! Generic variable bit array implementation. \n | |
| 8 //! Not very efficient to handle lots of items set to true but offers fast searches for true values and accepts arbitrary indexes, contrary to bit_array_bittable. Note that searches for false values are relatively inefficient. | |
| 9 class bit_array_var_impl : public bit_array_var { | |
| 10 public: | |
| 11 bit_array_var_impl( ) {} | |
| 12 bit_array_var_impl( const bit_array & source, size_t sourceCount); | |
| 13 bool get(t_size n) const; | |
| 14 t_size find(bool val,t_size start,t_ssize count) const; | |
| 15 void set(t_size n,bool val); | |
| 16 void set(t_size n) {m_data += n;} | |
| 17 void unset(t_size n) {m_data -= n;} | |
| 18 t_size get_true_count() const {return m_data.get_count();} | |
| 19 void clear() {m_data.remove_all();} | |
| 20 private: | |
| 21 avltree_t<t_size> m_data; | |
| 22 }; | |
| 23 | |
| 24 | |
| 25 //! Specialized implementation of bit_array. \n | |
| 26 //! Indended for scenarios where fast searching for true values in a large list is needed, combined with low footprint regardless of the amount of items. | |
| 27 //! Call add() repeatedly with the true val indexes. If the indexes were not added in increasing order, call presort() when done with adding. | |
| 28 class bit_array_flatIndexList : public bit_array { | |
| 29 public: | |
| 30 bit_array_flatIndexList(); | |
| 31 | |
| 32 void add( size_t n ); | |
| 33 | |
| 34 bool get(t_size n) const; | |
| 35 t_size find(bool val,t_size start,t_ssize count) const; | |
| 36 | |
| 37 void presort(); | |
| 38 | |
| 39 size_t get_count() const { return m_content.get_size(); } | |
| 40 | |
| 41 private: | |
| 42 bool _findNearestUp( size_t val, size_t & outIdx ) const; | |
| 43 bool _findNearestDown( size_t val, size_t & outIdx ) const; | |
| 44 bool _find( size_t val, size_t & outIdx ) const { | |
| 45 return pfc::bsearch_simple_inline_t( m_content, m_content.get_size(), val, outIdx); | |
| 46 } | |
| 47 | |
| 48 pfc::array_t< size_t, pfc::alloc_fast > m_content; | |
| 49 }; | |
| 50 } |
