18 #ifndef INC_KY_Kernel_Heap_BitSet2_H
19 #define INC_KY_Kernel_Heap_BitSet2_H
24 namespace Kaim {
namespace Heap {
83 static UPInt GetBitSetSize(UPInt dataSize, UPInt alignmentShift)
85 UPInt alignmentMask = (UPInt(1) << alignmentShift) - 1;
86 return (((dataSize + alignmentMask) >> alignmentShift) + 15) / 16;
89 static void Clear(
UInt32* buf, UPInt numWords)
91 memset(buf, 0,
sizeof(
UInt32) * numWords);
96 KY_INLINE
static unsigned GetValue(
const UInt32* buf, UPInt idx)
98 return (buf[idx >> 4] >> (2*idx & 30)) & 3;
103 KY_INLINE
static void ClearValue(
UInt32* buf, UPInt idx)
105 buf[idx >> 4] &= ~(
UInt32(3) << (2*idx & 30));
110 KY_INLINE
static void SetValue(
UInt32* buf, UPInt idx,
unsigned val)
112 UPInt wrd = idx >> 4;
113 UPInt rem = 2*idx & 30;
114 buf[wrd] = (buf[wrd] & ~(
UInt32(3) << rem)) | (
UInt32(val) << rem);
120 KY_INLINE
static void MarkFree(
UInt32* buf, UPInt start, UPInt num)
122 ClearValue(buf, start);
123 ClearValue(buf, start+num-1);
130 static void MarkBusy(
UInt32* buf, UPInt start, UPInt num)
136 SetValue(buf, start, 1);
140 SetValue(buf, start, 2);
146 SetValue(buf, start, 3);
147 SetValue(buf, start+1,
unsigned(num-3));
153 unsigned n6 = unsigned(num-6);
154 SetValue(buf, start, 3);
155 SetValue(buf, start+1, 3);
156 SetValue(buf, start+2, n6 >> 4);
157 SetValue(buf, start+3, (n6 >> 2) & 3);
158 SetValue(buf, start+4, n6 & 3);
162 SetValue(buf, start, 3);
163 SetValue(buf, start+1, 3);
164 SetValue(buf, start+2, 3);
165 buf[(2*start + 6 + 31) >> 5] =
UInt32(num);
169 SetValue(buf, start+num-1, 1);
177 static void MarkBusy(
UInt32* buf, UPInt start, UPInt num, UPInt alignShift)
183 SetValue(buf, start, 1);
187 SetValue(buf, start, 2);
188 SetValue(buf, start+1,
unsigned(alignShift+1));
194 SetValue(buf, start, 3);
195 SetValue(buf, start+1,
unsigned(num-3));
196 SetValue(buf, start+num-1,
unsigned(alignShift+1));
201 SetValue(buf, start, 3);
202 SetValue(buf, start+1, 3);
203 SetValue(buf, start+2, 0);
204 SetValue(buf, start+3, 0);
205 SetValue(buf, start+4,
unsigned(num-6));
206 SetValue(buf, start+num-1,
unsigned(alignShift+1));
213 unsigned n6 = unsigned(num-6);
214 SetValue(buf, start, 3);
215 SetValue(buf, start+1, 3);
216 SetValue(buf, start+2, n6 >> 4);
217 SetValue(buf, start+3, (n6 >> 2) & 3);
218 SetValue(buf, start+4, n6 & 3);
222 SetValue(buf, start, 3);
223 SetValue(buf, start+1, 3);
224 SetValue(buf, start+2, 3);
225 buf[(2*start + 6 + 31) >> 5] =
UInt32(num);
227 unsigned a = unsigned(alignShift << 1) | 1;
228 SetValue(buf, start+num-3, a >> 4);
229 SetValue(buf, start+num-2, (a >> 2) & 3);
230 SetValue(buf, start+num-1, a & 3);
239 static UPInt GetBlockSize(
const UInt32* buf, UPInt start)
242 size = GetValue(buf, start);
247 size = GetValue(buf, start+1);
252 size = GetValue(buf, start+2);
255 return 6 + ((size << 4) |
256 (GetValue(buf, start+3) << 2) |
257 GetValue(buf, start+4));
259 return buf[(2*start + 6 + 31) >> 5];
263 static unsigned GetAlignShift(
const UInt32* buf, UPInt start, UPInt num)
267 return GetValue(buf, start+num-1) - 1;
271 return (GetValue(buf, start+num-1) >> 1)|
272 (GetValue(buf, start+num-2) << 1)|
273 (GetValue(buf, start+num-3) << 3);
std::uint32_t UInt32
uint32_t
Definition: SF_Types.h:137
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17