summaryrefslogtreecommitdiff
path: root/src/util/allocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/allocator.h')
-rw-r--r--src/util/allocator.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/util/allocator.h b/src/util/allocator.h
index 27b21c0..64bad23 100644
--- a/src/util/allocator.h
+++ b/src/util/allocator.h
@@ -5,10 +5,23 @@
#include <functional>
#include "typedef.h"
-template < typename T >
+template <typename T>
+struct LIST_ITERATOR {
+ T* ptr;
+
+ LIST_ITERATOR( T* ptr ) : ptr( ptr ) {}
+ T& operator*() { return *ptr; }
+ T* operator->() { return ptr; }
+ LIST_ITERATOR& operator++() { ptr++; return *this; }
+ LIST_ITERATOR operator+=( U8 n ) { ptr += n; return *this; }
+ bool operator==( const LIST_ITERATOR& other ) { return ptr == other.ptr; }
+ bool operator!=( const LIST_ITERATOR& other ) { return ptr != other.ptr; }
+};
+
+template <typename T>
using QSORT_FN = std::function< U8( T*, T* ) >;
-template < typename T >
+template <typename T>
static U8 qsort_basic_sort( T* t1, T* t2 ) {
return (*t1 > *t2);
}
@@ -63,6 +76,13 @@ struct LIST {
size = 0;
}
+ LIST( U32 _size, const T* data ) {
+ data = (T*)malloc( sizeof( T ) * _size );
+ memcpy( data, data, _size * sizeof( T ) );
+ size = _size;
+ capacity = _size;
+ }
+
LIST( const LIST<T>& other ) {
if( !other.capacity || !other.size ) {
capacity = 1;
@@ -91,6 +111,7 @@ struct LIST {
capacity = 1;
size = 0;
data = (T*)malloc( sizeof( T ) );
+ memset( data, 0, sizeof( T ) );
return *this;
}
@@ -106,6 +127,10 @@ struct LIST {
free( data );
}
+ T at( U32 index ) {
+ return data[index];
+ }
+
void reserve( U32 count ) {
if( capacity >= count )
return;
@@ -320,4 +345,12 @@ struct LIST {
ret.sort( fn );
return ret;
}
+
+ LIST_ITERATOR<T> begin() {
+ return LIST_ITERATOR<T>( data );
+ }
+
+ LIST_ITERATOR<T> end() {
+ return LIST_ITERATOR<T>( data + size );
+ }
};