summaryrefslogtreecommitdiff
path: root/Source/Library/Common/Heap-index.class.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Library/Common/Heap-index.class.cpp')
-rw-r--r--Source/Library/Common/Heap-index.class.cpp51
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);
+ }
+}