diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-18 18:39:52 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-18 18:39:52 +0200 |
commit | ccf807eb4ff541bb849c4f370d34123cb23d7d76 (patch) | |
tree | 7f97fcf3f83ef1efcdc0ae72e11aab1f8332a667 /Source/Library/Common/Heap-index.class.cpp | |
parent | eb7b832d47bcbd74181028c62e871d407ba63a23 (diff) | |
download | Melon-ccf807eb4ff541bb849c4f370d34123cb23d7d76.tar.gz Melon-ccf807eb4ff541bb849c4f370d34123cb23d7d76.zip |
Heap included as well in userland library
Diffstat (limited to 'Source/Library/Common/Heap-index.class.cpp')
-rw-r--r-- | Source/Library/Common/Heap-index.class.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/Library/Common/Heap-index.class.cpp b/Source/Library/Common/Heap-index.class.cpp new file mode 100644 index 0000000..3280736 --- /dev/null +++ b/Source/Library/Common/Heap-index.class.cpp @@ -0,0 +1,51 @@ +#include "Heap.class.h" + +/* + * Implementation of the functions for managing heap index + */ + +void Heap::insertIntoIndex(heap_header_t *e) { + //If index is full, return + if ((m_index.size * sizeof(heap_header_t*) + (u32int)m_index.data) >= m_start) return; + + u32int iterator = 0; + while (iterator < m_index.size && m_index.data[iterator]->size < e->size) { + if (m_index.data[iterator] == e) return; + iterator++; + } + if (iterator == m_index.size) { + m_index.data[m_index.size++] = e; + } else { + u32int pos = iterator; + iterator = m_index.size; + while (iterator > pos) { + m_index.data[iterator] = m_index.data[iterator - 1]; + iterator--; + } + m_index.size++; + m_index.data[pos] = e; + } +} + +u32int Heap::findIndexEntry(heap_header_t *e) { + for (u32int i = 0; i < m_index.size; i++) { + if (m_index.data[i] == e) + return i; + } + return (u32int) - 1; +} + +void Heap::removeFromIndex(u32int idx) { + m_index.size--; + while (idx < m_index.size) { + m_index.data[idx] = m_index.data[idx + 1]; + idx++; + } +} + +void Heap::removeFromIndex(heap_header_t *e) { + u32int i = findIndexEntry(e); + if (i != (u32int) - 1) { + removeFromIndex(i); + } +} |