about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@mozilla.com>2010-07-27 23:05:13 -0700
committerGraydon Hoare <graydon@mozilla.com>2010-07-28 20:30:28 -0700
commit7ead107290a29811aee2cd6d170dacec45e0d67f (patch)
treef5671282320870efbe5cf98bd7e8958b20155b31
parentdfcf21ca821ee781074139222b3391dae40bf835 (diff)
downloadrust-7ead107290a29811aee2cd6d170dacec45e0d67f.tar.gz
rust-7ead107290a29811aee2cd6d170dacec45e0d67f.zip
array_list improvements.
-rw-r--r--src/rt/util/array_list.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/rt/util/array_list.h b/src/rt/util/array_list.h
index 04fd833f8b6..e6ce55ab792 100644
--- a/src/rt/util/array_list.h
+++ b/src/rt/util/array_list.h
@@ -14,20 +14,24 @@ public:
     ~array_list();
     size_t size();
     int32_t append(T value);
+    int32_t push(T value);
+    T pop();
     T replace(T old_value, T new_value);
     int32_t index_of(T value);
+    bool is_empty();
     T & operator[](size_t index);
 };
 
 template<typename T>
 array_list<T>::array_list() {
+    _size = 0;
     _capacity = INITIAL_CAPACITY;
     _data = (T *) malloc(sizeof(T) * _capacity);
 }
 
 template<typename T>
 array_list<T>::~array_list() {
-    delete _data;
+    free(_data);
 }
 
 template<typename T> size_t
@@ -37,6 +41,11 @@ array_list<T>::size() {
 
 template<typename T> int32_t
 array_list<T>::append(T value) {
+    return push(value);
+}
+
+template<typename T> int32_t
+array_list<T>::push(T value) {
     if (_size == _capacity) {
         _capacity = _capacity * 2;
         _data = (T *) realloc(_data, _capacity * sizeof(T));
@@ -45,6 +54,12 @@ array_list<T>::append(T value) {
     return _size - 1;
 }
 
+template<typename T> T
+array_list<T>::pop() {
+    T value = _data[-- _size];
+    return value;
+}
+
 /**
  * Replaces the old_value in the list with the new_value.
  * Returns the old_value if the replacement succeeded, or NULL otherwise.
@@ -74,4 +89,9 @@ array_list<T>::operator[](size_t index) {
     return _data[index];
 }
 
+template<typename T> bool
+array_list<T>::is_empty() {
+    return _size == 0;
+}
+
 #endif /* ARRAY_LIST_H */