Felix Brendel 5 anni fa
parent
commit
b766118a1f
1 ha cambiato i file con 30 aggiunte e 2 eliminazioni
  1. +30
    -2
      arraylist.hpp

+ 30
- 2
arraylist.hpp Vedi File

@@ -1,5 +1,6 @@
#pragma once
#include <stdlib.h>
#include <initializer_list>
#include "types.hpp"

template <typename type>
@@ -16,10 +17,9 @@ struct Array_List {

void dealloc() {
free(data);
data = 0;
data = nullptr;
}


void clear() {
next_index = 0;
}
@@ -68,6 +68,16 @@ struct Array_List {
return data[index];
}

static Array_List<type> alloc_from(std::initializer_list<type> l) {
Array_List<type> ret;
ret.alloc(l.size());
for (auto e : l) {
ret.append(e);
}
ret.auto_free = true;
return ret;
}

void _merge(u32 start, u32 mid, u32 end) {
u32 start2 = mid + 1;

@@ -137,3 +147,21 @@ struct Array_List {
return middle;
}
};


template <typename type>
struct Auto_Array_List : public Array_List<type> {
Auto_Array_List() = default;

Auto_Array_List(std::initializer_list<type> l) {
this->alloc(l.size());
for (type e : l) {
this->append(e);
}
}

~Auto_Array_List() {
free(this->data);
this->data = nullptr;
}
};

Caricamento…
Annulla
Salva