diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-18 15:27:34 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-18 15:27:34 +0200 |
commit | 323e12f1f9ab33df15dcfed210e807561d98fa8c (patch) | |
tree | 7d76e6932d4a979a1f2bfafc94478b66b1479bbc /Source/Library/Common/OrderedArray.class.cpp | |
parent | bc2eccdd11c27029096fb3e891073503eb269e27 (diff) | |
download | Melon-323e12f1f9ab33df15dcfed210e807561d98fa8c.tar.gz Melon-323e12f1f9ab33df15dcfed210e807561d98fa8c.zip |
Re-organized everything
Diffstat (limited to 'Source/Library/Common/OrderedArray.class.cpp')
-rw-r--r-- | Source/Library/Common/OrderedArray.class.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Source/Library/Common/OrderedArray.class.cpp b/Source/Library/Common/OrderedArray.class.cpp new file mode 100644 index 0000000..8b8f24f --- /dev/null +++ b/Source/Library/Common/OrderedArray.class.cpp @@ -0,0 +1,54 @@ +template <typename T> +OrderedArray<T>::OrderedArray(u32int max_size) { + m_array = (T*)Memory::alloc(max_size * sizeof(T*)); + m_size = 0; + m_maxSize = max_size; +} + +template <typename T> +OrderedArray<T>::OrderedArray(T **addr, u32int max_size) { + m_array = addr; + memset((u8int*)addr, 0, max_size * sizeof(T*)); + m_size = 0; + m_maxSize = max_size; +} + +template <typename T> +OrderedArray<T>::~OrderedArray() { + //Free memory +} + +template <typename T> +void OrderedArray<T>::insert(T *element) { + if (m_size == m_maxSize) return; //Array is full + u32int iterator = 0; + while (iterator < m_size && *(m_array[iterator]) < *element) { + iterator++; + } + if (iterator == m_size) { + m_array[m_size++] = element; + } else { + u32int pos = iterator; + while (iterator < m_size) { + iterator++; + m_array[iterator] = m_array[iterator - 1]; + } + m_size++; + m_array[pos] = element; + } +} + +template <typename T> +T *OrderedArray<T>::lookup(int index) { + return m_array[index]; +} + +template <typename T> +void OrderedArray<T>::remove(int index) { + m_size--; + while (index < m_size) { + m_array[index] = m_array[index + 1]; + index++; + } +} + |