27 #ifndef __dgHeapBase__ 28 #define __dgHeapBase__ 33 #include "common/util.h" 38 template <
class OBJECT,
class KEY>
45 RECORD(KEY key,
const OBJECT &obj)
46 : m_key(key), m_obj(obj) {
51 dgHeapBase(
const void *
const buffer, dgInt32 sizeInBytes);
55 DG_CLASS_ALLOCATOR(allocator)
59 KEY
Value(dgInt32 i = 0)
const;
60 dgInt32 GetCount()
const;
61 dgInt32 GetMaxCount()
const;
62 const OBJECT &operator[](dgInt32 i)
const;
63 OBJECT &operator[](dgInt32 i);
64 dgInt32 Find(OBJECT &obj);
65 dgInt32 Find(KEY key);
74 template <
class OBJECT,
class KEY>
78 dgDownHeap(
const void *
const buffer, dgInt32 sizeInBytes);
81 void Push(OBJECT &obj, KEY key);
83 void Remove(dgInt32 Index);
85 #ifdef DG_HEAP_SANITY_CHECK 90 template <
class OBJECT,
class KEY>
94 dgUpHeap(
const void *
const buffer, dgInt32 sizeInBytes);
97 void Push(OBJECT &obj, KEY key);
99 void Remove(dgInt32 Index);
101 #ifdef DG_HEAP_SANITY_CHECK 108 template <
class OBJECT,
class KEY>
111 m_allocator = allocator;
112 m_pool = (
RECORD *)m_allocator->Malloc(maxElements *
sizeof(
RECORD));
113 m_maxCount = maxElements;
117 template <
class OBJECT,
class KEY>
123 m_maxCount = dgInt32(sizeInBytes /
sizeof(
RECORD));
127 template <
class OBJECT,
class KEY>
130 m_allocator->Free(m_pool);
135 template <
class OBJECT,
class KEY>
137 return m_pool[i].m_key;
141 template <
class OBJECT,
class KEY>
147 template <
class OBJECT,
class KEY>
157 template <
class OBJECT,
class KEY>
159 return m_pool[0].m_key;
163 template <
class OBJECT,
class KEY>
169 template <
class OBJECT,
class KEY>
177 for (dgInt32 i = 0; i < m_curCount; i ++) {
178 if (m_pool[i].obj == obj) {
186 template <
class OBJECT,
class KEY>
191 NEWTON_ASSERT(m_curCount <= 32);
192 for (dgInt32 i = 0; i < m_curCount; i ++) {
193 if (m_pool[i].m_key == key) {
201 template <
class OBJECT,
class KEY>
203 NEWTON_ASSERT(i <= m_curCount);
204 return m_pool[i].m_obj;
207 template <
class OBJECT,
class KEY>
209 NEWTON_ASSERT(i <= m_curCount);
210 return m_pool[i].m_obj;
219 template <
class OBJECT,
class KEY>
224 template <
class OBJECT,
class KEY>
230 template <
class OBJECT,
class KEY>
238 NEWTON_ASSERT(cc < cm);
254 #ifdef DG_HEAP_SANITY_CHECK 255 NEWTON_ASSERT(SanityCheck());
260 template <
class OBJECT,
class KEY>
267 for (k = index + 1; k <= (dgHeapBase<OBJECT, KEY>::m_curCount >> 1); k = j) {
281 #ifdef DG_HEAP_SANITY_CHECK 282 NEWTON_ASSERT(SanityCheck());
287 template <
class OBJECT,
class KEY>
294 for (k = 1; k <= (dgHeapBase<OBJECT, KEY>::m_curCount >> 1); k = j) {
308 #ifdef DG_HEAP_SANITY_CHECK 309 NEWTON_ASSERT(SanityCheck());
315 template <
class OBJECT,
class KEY>
319 for (dgInt32 i = 1; i < count; i ++) {
330 for (dgInt32 i = 0; i < count / 2; i ++) {
340 #ifdef DG_HEAP_SANITY_CHECK 341 NEWTON_ASSERT(SanityCheck());
345 #ifdef DG_HEAP_SANITY_CHECK 346 template <
class OBJECT,
class KEY>
348 for (dgInt32 i = 0; i < dgHeapBase<OBJECT, KEY>::m_curCount / 2; i ++) {
371 template <
class OBJECT,
class KEY>
376 template <
class OBJECT,
class KEY>
381 #ifdef DG_HEAP_SANITY_CHECK 382 template <
class OBJECT,
class KEY>
384 for (dgInt32 i = 0; i < dgHeapBase<OBJECT, KEY>::m_curCount / 2; i ++) {
399 template <
class OBJECT,
class KEY>
408 NEWTON_ASSERT(cc < cm);
423 #ifdef DG_HEAP_SANITY_CHECK 424 NEWTON_ASSERT(SanityCheck());
429 template <
class OBJECT,
class KEY>
432 for (dgInt32 i = 1; i < count; i ++) {
443 for (dgInt32 i = 0; i < count / 2; i ++) {
453 #ifdef DG_HEAP_SANITY_CHECK 454 NEWTON_ASSERT(SanityCheck());
459 template <
class OBJECT,
class KEY>
466 for (k = index + 1; k <= (dgHeapBase<OBJECT, KEY>::m_curCount >> 1); k = j) {
480 #ifdef DG_HEAP_SANITY_CHECK 481 NEWTON_ASSERT(SanityCheck());
486 template <
class OBJECT,
class KEY>
493 for (k = 1; k <= (dgHeapBase<OBJECT, KEY>::m_curCount >> 1); k = j) {
507 #ifdef DG_HEAP_SANITY_CHECK 508 NEWTON_ASSERT(SanityCheck());
Definition: dgMemory.h:80