Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cBitArray.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cBitArray_H
7 #define _INC_cBitArray_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
15 #include "GrayCore/include/cBits.h"
17 
18 namespace Gray
19 {
21 }
22 
23 namespace GrayLib
24 {
26 
28  {
32 
33  typedef cBitArrayStatic THIS_t;
34 
35  public:
36  // Get the largest integral integer type. like INTMAX_t but for atomic instructions.
37 #if defined(USE_64BIT)
38  typedef UINT64 BLOCK_t;
39  typedef INT64 BLOCKI_t;
40  typedef UINT32 BLOCKH_t;
41 #elif defined(_WIN16)
42  typedef UINT16 BLOCK_t;
43  typedef INT16 BLOCKI_t;
44  typedef BYTE BLOCKH_t;
45 #else // else assume we are 32 bit architecture
46  typedef UINT32 BLOCK_t;
47  typedef INT32 BLOCKI_t;
48  typedef WORD BLOCKH_t;
49 #endif
50 
51  // On some architectures we can even do some double sized math. Though its not fully consistent and optimal.
52 #if defined(USE_64BIT)
53 
54 #if ( defined(__MSC_VER) && ( defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64)))
55  // There is no __MSC_VER 128 bit type.
56 #endif
57 
58 #if ( defined(__GNUC__) && ( \
59  defined(__amd64__) || defined(__x86_64__) || \
60  defined(__ppc64__) || defined(__powerpc64__) || \
61  defined(__ia64__) || defined(__alpha__) || \
62  (defined(__sparc__) && defined(__arch64__)) || \
63  defined(__s390x__) ) )
64  typedef unsigned int BLOCKDBL_t __attribute__((mode(TI))); // 128 bit type.
65 #define GRAY_BLOCK_UDBL
66 #endif
67 
68 #elif defined(_WIN16)
69  typedef UINT32 BLOCKD_t; // assume all 16 bit systems do 32 bit types.
70 #define GRAY_BLOCK_UDBL
71 #else // else assume we are 32 bit architecture
72 #ifdef USE_INT64 // assume all 32 bit systems do 64 bit types ?
73  typedef UINT64 BLOCKDBL_t;
74 #define GRAY_BLOCK_UDBL
75 #endif
76 #endif
77 
78  typedef unsigned int BLOCK_ENUM_t;
79  static const BLOCK_ENUM_t k_BLOCK_MAX = 8096;
80  static const size_t k_SIZE_MAX = k_BLOCK_MAX * sizeof(BLOCK_t);
81  static const BIT_ENUM_t k_BIT_MAX = k_SIZE_MAX * 8;
82 
83  static const cBitArrayStatic k_Zero; // (0, nullptr, true)
84  static const BLOCK_t k_OneBlock = 1;
85 
86  static const BIT_ENUM_t k_BLOCK_BITS = (BIT_ENUM_t)(sizeof(BLOCK_t) * 8);
87  static const BIT_ENUM_t k_BLOCKH_BITS = (BIT_ENUM_t)(sizeof(BLOCKH_t) * 8);
88 
89  private:
90  bool m_bStatic;
91  BLOCK_ENUM_t m_nBlocks;
92  BLOCK_t* m_pBlocks;
93 
94  public:
95  static inline BLOCK_ENUM_t GetBlocksFromBits(BIT_ENUM_t nBits) noexcept
96  {
98 #define BLOCKS_FROM_BITS(nBits) ((cBitArrayStatic::BLOCK_ENUM_t)(((nBits) + (cBitArrayStatic::k_BLOCK_BITS - 1)) / cBitArrayStatic::k_BLOCK_BITS)) // Macro for use in array sizing.
99  return BLOCKS_FROM_BITS(nBits);
100  }
101  static inline BLOCK_ENUM_t GetBlocksFromBytes(size_t nBytes) noexcept
102  {
104  return (BLOCK_ENUM_t)((nBytes + (sizeof(BLOCK_t) - 1)) / sizeof(BLOCK_t));
105  }
106  static inline bool IsReasonableBlockQty(BLOCK_ENUM_t nBlocks) noexcept
107  {
109  return IS_INDEX_GOOD(nBlocks, k_BLOCK_MAX);
110  }
111 
112  protected:
113  inline bool IsValidBlockIndex(BLOCK_ENUM_t i) const noexcept
114  {
115  return IS_INDEX_GOOD(i, m_nBlocks);
116  }
117 
118  void SetBlockSizeReAlloc(BLOCK_ENUM_t nBlocksNew);
119  void SetBlockSizeUninit(BLOCK_ENUM_t nBlocksNew);
120  void SetBlockSizeGrow(BLOCK_ENUM_t nBlocksNew);
121 
123  {
126  while (nBlocks > 0 && GetBlockInt(nBlocks - 1) == 0)
127  nBlocks--;
128  return nBlocks;
129  }
131  {
134  return FindUsedBlocksQty(get_BlocksCap());
135  }
136 
137  public:
138  cBitArrayStatic() noexcept
139  : m_bStatic(false)
140  , m_nBlocks(0)
141  , m_pBlocks(nullptr)
142  {
144  }
145  explicit cBitArrayStatic(BIT_ENUM_t nBits)
146  : m_bStatic(false)
147  , m_nBlocks(GetBlocksFromBits(nBits))
148  {
149  m_pBlocks = new BLOCK_t[m_nBlocks];
150  SetZeroAll();
151  }
152  cBitArrayStatic(BIT_ENUM_t nBits, BLOCK_t uValueMask)
153  : m_bStatic(false)
154  , m_nBlocks(GetBlocksFromBits(nBits))
155  {
157  ASSERT(IsReasonableBlockQty(m_nBlocks));
158  m_pBlocks = new BLOCK_t[m_nBlocks];
159  if (m_nBlocks > 0)
160  {
161  m_pBlocks[0] = uValueMask;
162  cValArray::FillQty<BLOCK_t>(m_pBlocks + 1, m_nBlocks - 1, 0);
163  }
164  }
165  cBitArrayStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t* pData)
166  : m_bStatic(false)
167  , m_nBlocks(nBlocks)
168  , m_pBlocks(new BLOCK_t[nBlocks])
169  {
170  // copy data.
171  ASSERT(IsReasonableBlockQty(m_nBlocks));
172  cValArray::CopyQty<BLOCK_t>(m_pBlocks, pData, nBlocks);
173  }
174  cBitArrayStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t* pBlocksInit, bool bStatic)
175  : m_bStatic(true)
176  , m_nBlocks(nBlocks)
177  , m_pBlocks(const_cast<BLOCK_t*>(pBlocksInit))
178  {
179  // static data init.
180  ASSERT(bStatic); // MUST be true
181  ASSERT(IsReasonableBlockQty(m_nBlocks));
182  ASSERT((m_nBlocks > 0) ^ (m_pBlocks == nullptr));
183  }
184 
186  : m_bStatic(ref.m_bStatic)
187  , m_nBlocks(ref.m_nBlocks)
188  , m_pBlocks(ref.m_bStatic ? ref.m_pBlocks : (new BLOCK_t[ref.m_nBlocks]))
189  {
190  // copy constructor. like SetCopyBits
191  ASSERT(IsReasonableBlockQty(m_nBlocks));
192  if (!m_bStatic)
193  {
194  cValArray::CopyQty<BLOCK_t>(m_pBlocks, ref.m_pBlocks, m_nBlocks);
195  }
196  else
197  {
198  ASSERT((m_nBlocks > 0) ^ (m_pBlocks == nullptr));
199  }
200  }
201  cBitArrayStatic(THIS_t&& ref) noexcept
202  : m_bStatic(ref.m_bStatic)
203  , m_nBlocks(ref.m_nBlocks)
204  , m_pBlocks(ref.m_pBlocks)
205  {
207  DEBUG_CHECK(&ref != this);
208  ref.m_bStatic = false;
209  ref.m_nBlocks = 0;
210  ref.m_pBlocks = nullptr;
211  }
213  {
215  SetNullVal();
216  }
217 
218  inline bool isNullVal() const noexcept
219  {
220  // isEmptyBits
221  return m_pBlocks == nullptr;
222  }
223  inline bool isZeroVal() const noexcept
224  {
225  // Is null or zero.
226  return isNullVal() || (m_nBlocks <= 0);
227  }
228  inline BLOCK_ENUM_t get_BlocksCap() const noexcept
229  {
231  return m_nBlocks;
232  }
233  inline size_t get_BytesCap() const noexcept
234  {
235  return m_nBlocks * sizeof(BLOCK_t);
236  }
238  {
239  ASSERT(IsValidBlockIndex(i));
240  return m_pBlocks[i];
241  }
242  const BLOCK_t* get_BlockPtrC() const noexcept
243  {
245  return m_pBlocks;
246  }
248  {
250  ASSERT(!isReadOnly()); // never allowed for read only values.
251  return m_pBlocks;
252  }
254  {
257  ASSERT(!isReadOnly());
258  ASSERT(IsValidBlockIndex(i));
259  return m_pBlocks[i];
260  }
261 
262  UINT32 GetU32Int(BLOCK_ENUM_t j) const
263  {
265 #if defined(USE_64BIT) // 64 bit
266 #ifdef USE_LITTLE_ENDIAN
267  ASSERT(IsValidBlockIndex(j / 2));
268  return ((const UINT32*)m_pBlocks)[j];
269 #else
270  BLOCK_t v = GetBlockInt(j / 2);
271  return (j & 1) ? (v >> 32) : ((UINT32)v);
272 #endif
273 #else
274  return GetBlockInt(j);
275 #endif
276  }
277  void SetU32Int(BLOCK_ENUM_t j, UINT32 val32)
278  {
280 #if defined(USE_64BIT) // 64 bit
281  ASSERT(!isReadOnly());
282 #ifdef USE_LITTLE_ENDIAN
283  ASSERT(IsValidBlockIndex(j / 2));
284  ((UINT32*)m_pBlocks)[j] = val32;
285 #else
286  // Fix big endian problem.
287  BLOCK_ENUM_t i = j / 2;
288  BLOCK_t v = GetBlockInt(i);
289  if (j & 1)
290  {
291  v &= 0x00000000FFFFFFFF;
292  v |= ((BLOCK_t)val32) << 32;
293  }
294  else
295  {
296  v &= 0xFFFFFFFF00000000;
297  v |= val32;
298  }
299  m_pBlocks[i] = v;
300 #endif
301 #else
302  RefBlockInt(j) = val32;
303 #endif
304  }
305 
306  const THIS_t& operator = (const THIS_t& ref)
307  {
309  SetCopyBits(ref);
310  return *this;
311  }
312  THIS_t& operator = (THIS_t&& ref)
313  {
315  m_bStatic = ref.m_bStatic;
316  m_nBlocks = ref.m_nBlocks;
317  m_pBlocks = ref.m_pBlocks;
318  ref.m_pBlocks = nullptr;
319  ref.m_bStatic = false;
320  ref.m_nBlocks = 0;
321  return *this;
322  }
323 
324  bool isStatic() const noexcept
325  {
327  return m_bStatic;
328  }
329  void SetBlocksStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t* pBlocks);
330 
331  bool isReadOnly() const noexcept
332  {
335  return false;
336  }
337  BIT_ENUM_t get_BitsCap() const noexcept
338  {
340  return((BIT_ENUM_t)(get_BlocksCap() * k_BLOCK_BITS));
341  }
342  bool IsValidBit(BIT_ENUM_t nBit) const noexcept
343  {
345  return IS_INDEX_GOOD(nBit, get_BitsCap());
346  }
347 
348  bool IsSet(BIT_ENUM_t nBit) const
349  {
353  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
354  if (!IsValidBlockIndex(nBlock))
355  return false;
356  return cBits::IsSet(GetBlockInt(nBlock), nBit % k_BLOCK_BITS);
357  }
358  bool isOdd() const
359  {
360  if (m_nBlocks <= 0)
361  return false;
362  return(m_pBlocks[0] & 1);
363  }
364 
365  void ClrBit(BIT_ENUM_t nBit)
366  {
368  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
369  if (!IsValidBlockIndex(nBlock)) // just ignore this clear.
370  return;
371  RefBlockInt(nBlock) &= ~(cBits::Mask1<BLOCK_t>(nBit % k_BLOCK_BITS));
372  }
373  void SetBit(BIT_ENUM_t nBit)
374  {
376  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
377  RefBlockInt(nBlock) |= cBits::Mask1<BLOCK_t>(nBit % k_BLOCK_BITS);
378  }
379  bool SetBitRet(BIT_ENUM_t nBit);
380  void ModBit(BIT_ENUM_t nBit, bool bVal)
381  {
384  if (bVal)
385  SetBit(nBit);
386  else
387  ClrBit(nBit);
388  }
389 
390  void SetNullVal() noexcept;
391  void SetZeroAll()
392  {
394  ASSERT(!isReadOnly());
395  cValArray::ZeroQty<BLOCK_t>(get_BlockPtr(), get_BlocksCap());
396  }
397  void SetAll1()
398  {
400  ASSERT(!isReadOnly());
401  ::memset(get_BlockPtr(), 0xFF, get_BlocksCap() * sizeof(BLOCK_t));
402  }
403 
405  {
407  SetBlockSizeUninit(GetBlocksFromBits(nBits));
408  SetZeroAll();
409  }
410 
411  void SetInvertBytes(size_t nSize);
412  void SetCopyBits(const THIS_t& ref);
413  };
414 
416  {
423 
424  typedef cBitArray THIS_t;
425  typedef cBitArrayStatic SUPER_t;
426 
427  protected:
429 
430  public:
431  bool isHighBlockUseExact() const
432  {
435  return FindUsedBlocksQty() == m_nBlocksUse;
436  }
437  bool isHighBlockUseValid() const
438  {
441  return FindUsedBlocksQty() <= m_nBlocksUse;
442  }
444  {
446 #if 0
447  BLOCK_ENUM_t nBlocksUse = FindUsedBlocksQty();
448  DEBUG_ASSERT(nBlocksUse == m_nBlocksUse, __FUNCTION__); // m_nBlocksUse Accurate?
449  return nBlocksUse;
450 #else
451  ASSERT(isHighBlockUseValid());
452  return m_nBlocksUse;
453 #endif
454  }
456  {
459  while (m_nBlocksUse > 0 && GetBlockInt(m_nBlocksUse - 1) == 0)
460  m_nBlocksUse--;
461  DEBUG_ASSERT(isHighBlockUseExact(), __FUNCTION__); // Accurate?
462  }
463  void UpdateBlocksUseMax(BLOCK_ENUM_t nBlocksUseMax)
464  {
466  DEBUG_ASSERT(nBlocksUseMax <= get_BlocksCap(), __FUNCTION__);
467  m_nBlocksUse = nBlocksUseMax;
468  UpdateBlocksUse();
469  }
471  {
473  m_nBlocksUse = get_BlocksCap();
474  UpdateBlocksUse();
475  }
477  {
480  SetBlockSizeGrow(nBlock + 1); // set m_nBlocksUse
481  return RefBlockInt(nBlock);
482  }
483 
484  protected:
485 
486  void put_BlocksUse(BLOCK_ENUM_t nBlocksUse)
487  {
489  m_nBlocksUse = nBlocksUse;
490  DEBUG_ASSERT(isHighBlockUseExact(), __FUNCTION__); // Accurate?
491  }
492 
494  {
496  if (IS_INDEX_BAD(nBlock, m_nBlocksUse))
497  return 0;
498  return GetBlockInt(nBlock);
499  }
501  {
503  if (nVal == 0)
504  return;
505  if (m_nBlocksUse >= get_BlocksCap())
506  {
507  SetBlockSizeReAlloc(m_nBlocksUse + 1);
508  }
509  RefBlockInt(m_nBlocksUse) = nVal;
510  m_nBlocksUse++;
511  }
513  {
514  if (nVal == 0)
515  {
516  if (IS_INDEX_BAD(i, m_nBlocksUse)) // If i >= m_nBlocksUse, no effect.
517  return;
518  RefBlockInt(i) = 0;
519  UpdateBlocksUse();
520  }
521  else
522  {
523  RefBlock(i) = nVal;
524  }
525  }
526 
527  public:
529  : m_nBlocksUse(0)
530  {
532  }
533  explicit cBitArray(BIT_ENUM_t nBits)
534  : SUPER_t(nBits)
535  , m_nBlocksUse(0)
536  {
537  }
538  cBitArray(BIT_ENUM_t nBits, BLOCK_t uValueMask)
539  : SUPER_t(nBits, uValueMask)
540  , m_nBlocksUse(uValueMask ? 1 : 0)
541  {
542  }
543  cBitArray(BLOCK_ENUM_t nBlocks, const BLOCK_t* pBlocks)
544  : SUPER_t(nBlocks, pBlocks)
545  {
547  m_nBlocksUse = nBlocks;
548  UpdateBlocksUse();
549  }
550  cBitArray(BLOCK_ENUM_t nBlocks, const BLOCK_t* pBlocks, bool bStatic)
551  : SUPER_t(nBlocks, pBlocks, bStatic)
552  {
554  ASSERT(bStatic);
555  m_nBlocksUse = nBlocks; // Can we assume this won't change? isHighBlockUseValid()
556  UpdateBlocksUse();
557  }
559  {
560  DEBUG_ASSERT(isHighBlockUseValid(), __FUNCTION__); // Accurate?
561  }
562 
563  static HRESULT GRAYCALL ReturnError(HRESULT hRes, const char* pszMsg);
564  void SetBlocksStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t* pBlocks);
565  void SetBlocksStatic(const cBitArrayStatic& b);
566 
567  HRESULT SetBlockSizeGrow(BLOCK_ENUM_t nBlocksNew);
568  HRESULT SetBlockSizeShrink(BLOCK_ENUM_t nBlocksNew);
569  void SetBlockSizeUse(BLOCK_ENUM_t nBlocksNew);
570 
571  bool IsEqual(const THIS_t& x) const
572  {
573  BLOCK_ENUM_t nBlocks = get_BlocksUse();
574  if (nBlocks != x.get_BlocksUse()) // Definitely unequal.
575  return false;
576  return cValArray::IsEqualQty(get_BlockPtrC(), x.get_BlockPtrC(), nBlocks);
577  }
578  bool IsEqualU(BLOCK_t x) const
579  {
581  BLOCK_ENUM_t nBlocks = get_BlocksUse();
582  if (nBlocks > 1) // Definitely unequal.
583  return false;
584  return GetBlockInt(0) == x;
585  }
586  bool operator ==(const THIS_t& x) const
587  {
588  return IsEqual(x);
589  }
590  bool operator !=(const THIS_t& x) const
591  {
592  return !IsEqual(x);
593  }
594 
595  bool isEmptyBits() const
596  {
599  return m_nBlocksUse == 0;
600  }
601 
602  bool IsSet(BIT_ENUM_t nBit) const
603  {
607  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
608  if (IS_INDEX_BAD(nBlock, m_nBlocksUse))
609  return false;
610  nBit %= k_BLOCK_BITS;
611  return cBits::IsSet(GetBlockInt(nBlock), nBit);
612  }
613 
614  BIT_ENUM_t get_Lowest1Bit() const;
615  BIT_ENUM_t get_Highest1Bit() const;
616 
618  {
620  BIT_ENUM_t nBits1 = 0;
621  for (BLOCK_ENUM_t nBlock = 0; nBlock < m_nBlocksUse; nBlock++)
622  {
623  nBits1 += cBits::Count1Bits(GetBlockInt(nBlock));
624  }
625  return nBits1;
626  }
627 
628  //****************************************************
629  // Modifiers.
630 
631  void SetBit(BIT_ENUM_t nBit)
632  {
634  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
635  RefBlock(nBlock) |= cBits::Mask1<BLOCK_t>(nBit % k_BLOCK_BITS);
636  }
637  void ClrBit(BIT_ENUM_t nBit)
638  {
640  BLOCK_ENUM_t nBlock = nBit / k_BLOCK_BITS;
641  if (IS_INDEX_BAD(nBlock, m_nBlocksUse))
642  return;
643  RefBlockInt(nBlock) &= ~(cBits::Mask1<BLOCK_t>(nBit % k_BLOCK_BITS));
644  UpdateBlocksUse();
645  }
646  void ModBit(BIT_ENUM_t nBit, bool bVal)
647  {
650  if (bVal)
651  SetBit(nBit);
652  else
653  ClrBit(nBit);
654  }
655 
656  void SetTruncateBits(BIT_ENUM_t nBits);
657 
658  HRESULT SetRandomBits(BIT_ENUM_t nBits, IRandomNoise* pRandom = nullptr);
660  {
662  if (nBits < 3 || nBits > k_BIT_MAX)
663  return E_INVALIDARG;
664  HRESULT hRes = SetRandomBits(nBits, pRandom);
665  SetBit(nBits - 1);
666  return hRes;
667  }
668 
669  void SetCopyBits(const THIS_t& ref);
670  HRESULT SetCopySecure(const THIS_t& val, bool assign);
671  static HRESULT GRAYCALL SwapSecure(THIS_t& X, THIS_t& Y, bool swap);
672 
673  void SetZeroAll()
674  {
675  // like SUPER_t::SetZeroAll
676  // Zero out the value but don't change the allocated size.
677  // Can't assume m_nBlocksUse is accurate. // cValArray::FillQty<BLOCK_t>(get_BlockPtr(), m_nBlocksUse, 0);
678  SUPER_t::SetZeroAll();
679  m_nBlocksUse = 0;
680  }
681  void SetNullVal()
682  {
683  // like SUPER_t::SetZeroAll but reallocates size.
684  m_nBlocksUse = 0;
685  SUPER_t::SetNullVal();
686  }
687 
688  size_t get_BinarySize() const
689  {
692  return cBits::GetSizeBytes(get_Highest1Bit());
693  }
694 
695  HRESULT GetBinaryBE(BYTE* pOut, size_t nSizeOut) const;
696  HRESULT GetBinaryBE(cHeapBlock& b) const;
697  HRESULT SetBinaryBE(const BYTE* pData, size_t nSize);
698  HRESULT SetBinaryLE(const BYTE* pData, size_t nSize);
699 
701  };
702 
703  // macros for storing embedded constants for cBitArrayStatic::SetBlocksStatic() in as little space as possible.
704  // build lists of cBitArray::BLOCK_t's from lists of BYTE's grouped by 8, 4 or 2
705  // similar to CUINT64() but will break into 32 or 64 bits
706  // Note: the constants are in little-endian order to be directly usable in cBitArray
707 
708 #if defined(USE_64BIT) // 64-bits BLOCK_t
709 
710 #define BLOCKS_FROM_BYTES( a, b, c, d, e, f, g, h ) \
711  ( (cBitArray::BLOCK_t) a << 0 ) | \
712  ( (cBitArray::BLOCK_t) b << 8 ) | \
713  ( (cBitArray::BLOCK_t) c << 16 ) | \
714  ( (cBitArray::BLOCK_t) d << 24 ) | \
715  ( (cBitArray::BLOCK_t) e << 32 ) | \
716  ( (cBitArray::BLOCK_t) f << 40 ) | \
717  ( (cBitArray::BLOCK_t) g << 48 ) | \
718  ( (cBitArray::BLOCK_t) h << 56 )
719 
720 #define BLOCK_FROM_BYTES( a, b, c, d ) BLOCKS_FROM_BYTES( a, b, c, d, 0, 0, 0, 0 )
721 
722 #else // else 32 bit int BLOCK_t.
723 
724 #define BLOCK_FROM_BYTES( a, b, c, d ) \
725  ( (cBitArray::BLOCK_t) a << 0 ) | \
726  ( (cBitArray::BLOCK_t) b << 8 ) | \
727  ( (cBitArray::BLOCK_t) c << 16 ) | \
728  ( (cBitArray::BLOCK_t) d << 24 )
729 
730 #define BLOCKS_FROM_BYTES( a, b, c, d, e, f, g, h ) BLOCK_FROM_BYTES( a, b, c, d ), BLOCK_FROM_BYTES( e, f, g, h )
731 
732 #endif // ! USE_64BIT
733 
734 };
735 #endif // _INC_cBitArray_H
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
#define IS_INDEX_BAD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:34
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define BLOCKS_FROM_BITS(nBits)
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
#define DEBUG_ASSERT(exp, sDesc)
Definition: cDebugAssert.h:93
Definition: cBitArray.h:28
void SetBit(BIT_ENUM_t nBit)
Definition: cBitArray.h:373
void SetBitsSizeZ(BIT_ENUM_t nBits)
Definition: cBitArray.h:404
static BLOCK_ENUM_t GetBlocksFromBits(BIT_ENUM_t nBits) noexcept
Definition: cBitArray.h:95
size_t get_BytesCap() const noexcept
Definition: cBitArray.h:233
cBitArrayStatic(BIT_ENUM_t nBits)
Definition: cBitArray.h:145
bool IsSet(BIT_ENUM_t nBit) const
Definition: cBitArray.h:348
bool IsValidBit(BIT_ENUM_t nBit) const noexcept
Definition: cBitArray.h:342
bool isNullVal() const noexcept
Definition: cBitArray.h:218
static bool IsReasonableBlockQty(BLOCK_ENUM_t nBlocks) noexcept
Definition: cBitArray.h:106
static BLOCK_ENUM_t GetBlocksFromBytes(size_t nBytes) noexcept
Definition: cBitArray.h:101
void SetU32Int(BLOCK_ENUM_t j, UINT32 val32)
Definition: cBitArray.h:277
~cBitArrayStatic()
Definition: cBitArray.h:212
static const cBitArrayStatic k_Zero
Definition: cBitArray.h:83
BIT_ENUM_t get_BitsCap() const noexcept
Definition: cBitArray.h:337
unsigned int BLOCK_ENUM_t
Type for the index of a BLOCK_t in the array. NOT bits BIT_ENUM_t.
Definition: cBitArray.h:78
cBitArrayStatic() noexcept
Definition: cBitArray.h:138
cBitArrayStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocksInit, bool bStatic)
Definition: cBitArray.h:174
bool isOdd() const
Definition: cBitArray.h:358
INT32 BLOCKI_t
The biggest signed type I can do atomic math on.
Definition: cBitArray.h:47
bool isReadOnly() const noexcept
Definition: cBitArray.h:331
void ModBit(BIT_ENUM_t nBit, bool bVal)
Definition: cBitArray.h:380
cBitArrayStatic(BLOCK_ENUM_t nBlocks, const BLOCK_t *pData)
Definition: cBitArray.h:165
bool IsValidBlockIndex(BLOCK_ENUM_t i) const noexcept
Definition: cBitArray.h:113
UINT32 GetU32Int(BLOCK_ENUM_t j) const
Definition: cBitArray.h:262
BLOCK_ENUM_t FindUsedBlocksQty() const
Definition: cBitArray.h:130
bool isZeroVal() const noexcept
Definition: cBitArray.h:223
BLOCK_t * get_BlockPtr()
Definition: cBitArray.h:247
void SetAll1()
Definition: cBitArray.h:397
cBitArrayStatic(const THIS_t &ref)
Definition: cBitArray.h:185
BLOCK_ENUM_t get_BlocksCap() const noexcept
Definition: cBitArray.h:228
cBitArrayStatic(BIT_ENUM_t nBits, BLOCK_t uValueMask)
Definition: cBitArray.h:152
BLOCK_ENUM_t FindUsedBlocksQty(BLOCK_ENUM_t nBlocks) const
Definition: cBitArray.h:122
const BLOCK_t * get_BlockPtrC() const noexcept
Definition: cBitArray.h:242
BLOCK_t GetBlockInt(BLOCK_ENUM_t i) const
Definition: cBitArray.h:237
UINT32 BLOCK_t
The biggest unsigned type I can do atomic math on for this architecture.
Definition: cBitArray.h:46
BLOCK_t & RefBlockInt(BLOCK_ENUM_t i)
Definition: cBitArray.h:253
bool isStatic() const noexcept
Definition: cBitArray.h:324
WORD BLOCKH_t
half sized BLOCK_t for multiplication overflows.
Definition: cBitArray.h:48
void ClrBit(BIT_ENUM_t nBit)
Definition: cBitArray.h:365
cBitArrayStatic(THIS_t &&ref) noexcept
Definition: cBitArray.h:201
Definition: cBitArray.h:416
HRESULT SetRandomBitsLarge(BIT_ENUM_t nBits, IRandomNoise *pRandom=nullptr)
Definition: cBitArray.h:659
void UpdateBlocksUse()
Definition: cBitArray.h:455
cBitArray(BIT_ENUM_t nBits, BLOCK_t uValueMask)
Definition: cBitArray.h:538
size_t get_BinarySize() const
Definition: cBitArray.h:688
BLOCK_ENUM_t m_nBlocksUse
Qty of blocks that is non zero. ASSUME anything above this is 0 blocks.
Definition: cBitArray.h:428
bool IsEqual(const THIS_t &x) const
Definition: cBitArray.h:571
void UpdateBlocksUseCap()
Definition: cBitArray.h:470
~cBitArray()
Definition: cBitArray.h:558
void AddBlockGrow(BLOCK_t nVal)
Definition: cBitArray.h:500
cBitArray(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks)
Definition: cBitArray.h:543
bool isEmptyBits() const
Definition: cBitArray.h:595
void SetNullVal()
Definition: cBitArray.h:681
bool IsSet(BIT_ENUM_t nBit) const
Definition: cBitArray.h:602
bool isHighBlockUseExact() const
Definition: cBitArray.h:431
void SetBit(BIT_ENUM_t nBit)
Definition: cBitArray.h:631
BLOCK_ENUM_t get_BlocksUse() const
Definition: cBitArray.h:443
BIT_ENUM_t get_Count1Bits() const
Definition: cBitArray.h:617
void ModBit(BIT_ENUM_t nBit, bool bVal)
Definition: cBitArray.h:646
void put_BlocksUse(BLOCK_ENUM_t nBlocksUse)
Definition: cBitArray.h:486
void UpdateBlocksUseMax(BLOCK_ENUM_t nBlocksUseMax)
Definition: cBitArray.h:463
cBitArray(BIT_ENUM_t nBits)
Definition: cBitArray.h:533
BLOCK_t & RefBlock(BLOCK_ENUM_t nBlock)
Definition: cBitArray.h:476
void SetZeroAll()
Definition: cBitArray.h:673
bool isHighBlockUseValid() const
Definition: cBitArray.h:437
bool IsEqualU(BLOCK_t x) const
Definition: cBitArray.h:578
void SetBlock(BLOCK_ENUM_t i, BLOCK_t nVal)
Definition: cBitArray.h:512
BLOCK_t GetBlock(BLOCK_ENUM_t nBlock) const
Definition: cBitArray.h:493
UNITTEST_FRIEND(cBitArray)
cBitArray()
Definition: cBitArray.h:528
cBitArray(BLOCK_ENUM_t nBlocks, const BLOCK_t *pBlocks, bool bStatic)
Definition: cBitArray.h:550
void ClrBit(BIT_ENUM_t nBit)
Definition: cBitArray.h:637
Definition: cHeap.h:156
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
DECLARE_INTERFACE(IRandomNoise)
unsigned int BIT_ENUM_t
Enumerate number of bits or address a single bit in some array of bits.
Definition: cBits.h:20
bool operator!=(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:254
bool operator==(const cTimeDouble &dt1, const cTimeDouble &dt2)
Definition: cTimeDouble.h:250
Definition: cRandom.h:19
Definition: cBits.h:48
static BIT_ENUM_t Count1Bits(TYPE nMask) noexcept
Definition: cBits.h:127
static constexpr size_t GetSizeBytes(BIT_ENUM_t nBits) noexcept
Definition: cBits.h:54
static constexpr bool IsSet(TYPE nVal, BIT_ENUM_t nBit) noexcept
Definition: cBits.h:77
static bool IsEqualQty(const TYPE *pArray1, const TYPE *pArray2, ITERATE_t nBlocks) noexcept
Definition: cValT.h:87