gwnavgeneration/common/bitarray_1024.h Source File

bitarray_1024.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef GwNavGen_BitArray_1024_H
10 #define GwNavGen_BitArray_1024_H
11 
12 
15 
16 
17 namespace Kaim
18 {
19 
20 
21 class BitArray_1024
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 public:
25  // KY_NULL as default value to avoid compilation error in KyArray instantiation
26  // but it should already be used with a valid Heap
27  BitArray_1024(MemoryHeap* heap = KY_NULL) : m_wordsCount(0), m_rootWord(0), m_words(KY_NULL), m_allocated(false), m_heap(heap)
28  {}
29 
30  ~BitArray_1024();
31 
32  KyResult Init(void* words, KyInt32 wordsCount);
33 
34  KyResult Init(KyInt32 wordsCount);
35 
36  void ClearBits();
37 
38  void SetBit(KyInt32 bit_idx)
39  {
40  KY_DEBUG_ASSERTN(bit_idx >= 0, ("bit_idx must be greater or equal to 0"));
41 
42  KyUInt32 word_idx = bit_idx >> 5; // x / 32
43  KyUInt32 bit_idx_in_word = bit_idx & 0x1F; // (1 << 5) - 1
44 
45  KY_DEBUG_ASSERTN(word_idx < (KyUInt32)m_wordsCount, ("word_idx out of bounds"));
46 
47  m_rootWord |= (1 << word_idx);
48  m_words[word_idx] |= (1 << bit_idx_in_word);
49  }
50 
51  KyInt32 GetBit(KyInt32 bit_idx) const
52  {
53  KyUInt32 word_idx = bit_idx >> 5; // x / 32
54  KyUInt32 bit_idx_in_word = bit_idx & 0x1F; // (1 << 5) - 1
55  return m_words[word_idx] & (1 << bit_idx_in_word);
56  }
57 
58  KyInt32 GetFirstBitIdx() const;
59 
60  KyInt32 GetLastBitIdx() const;
61 
62 private:
63  KyInt32 m_wordsCount;
64  KyUInt32 m_rootWord;
65  KyUInt32* m_words;
66  bool m_allocated;
67  MemoryHeap* m_heap;
68 };
69 
70 
71 }
72 
73 
74 #endif
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36