- File:
-
- 1 edited
-
src/libcfa/containers/vector.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/containers/vector.c
rbd34fc87 r60aa49a7 18 18 #include <stdlib> 19 19 20 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))21 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other);22 23 20 //------------------------------------------------------------------------------ 24 21 //Initialization 25 22 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 26 void ?{}(vector(T, allocator_t)*this)23 void ctor(vector(T, allocator_t) *const this) 27 24 { 28 (&this->storage){};25 ctor(&this->storage); 29 26 this->size = 0; 30 27 } 31 28 32 29 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 33 void ?{}(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 34 { 35 (&this->storage){ rhs.storage }; 36 copy_internal(this, &rhs); 37 } 38 39 // forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 40 // vector(T, allocator_t) ?=?(vector(T, allocator_t)* this, vector(T, allocator_t) rhs) 41 // { 42 // (&this->storage){}; 43 // copy_internal(this, &rhs); 44 // return *this; 45 // } 46 47 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 48 void ^?{}(vector(T, allocator_t)* this) 30 void dtor(vector(T, allocator_t) *const this) 49 31 { 50 32 clear(this); 51 ^(&this->storage){};33 dtor(&this->storage); 52 34 } 53 35 … … 55 37 //Modifiers 56 38 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 57 void push_back(vector(T, allocator_t) *this, T value)39 void push_back(vector(T, allocator_t) *const this, T value) 58 40 { 59 41 realloc_storage(&this->storage, this->size+1); … … 63 45 64 46 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 65 void pop_back(vector(T, allocator_t) *this)47 void pop_back(vector(T, allocator_t) *const this) 66 48 { 67 49 this->size--; 68 ^(&data(&this->storage)[this->size]){};50 DESTROY(data(&this->storage)[this->size]); 69 51 } 70 52 71 53 forall(otype T, otype allocator_t | allocator_c(T, allocator_t)) 72 void clear(vector(T, allocator_t) *this)54 void clear(vector(T, allocator_t) *const this) 73 55 { 74 56 for(size_t i = 0; i < this->size; i++) 75 57 { 76 ^(&data(&this->storage)[this->size]){};58 DESTROY(data(&this->storage)[this->size]); 77 59 } 78 60 this->size = 0; … … 80 62 81 63 //------------------------------------------------------------------------------ 82 //Internal Helpers83 84 forall(otype T, otype allocator_t | allocator_c(T, allocator_t))85 void copy_internal(vector(T, allocator_t)* this, vector(T, allocator_t)* other)86 {87 this->size = other->size;88 for(size_t i = 0; i < this->size; i++) {89 (&data(&this->storage)[this->size]){ data(&other->storage)[other->size] };90 }91 }92 93 //------------------------------------------------------------------------------94 64 //Allocator 95 65 forall(otype T) 96 void ?{}(heap_allocator(T)*this)66 void ctor(heap_allocator(T) *const this) 97 67 { 98 68 this->storage = 0; … … 101 71 102 72 forall(otype T) 103 void ?{}(heap_allocator(T)* this, heap_allocator(T) rhs) 104 { 105 this->capacity = rhs.capacity; 106 this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T)); 107 } 108 109 forall(otype T) 110 heap_allocator(T) ?=?(heap_allocator(T)* this, heap_allocator(T) rhs) 111 { 112 this->capacity = rhs.capacity; 113 this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T)); 114 return *this; 115 } 116 117 forall(otype T) 118 void ^?{}(heap_allocator(T)* this) 73 void dtor(heap_allocator(T) *const this) 119 74 { 120 75 free(this->storage); … … 122 77 123 78 forall(otype T) 124 inline void realloc_storage(heap_allocator(T) *this, size_t size)79 inline void realloc_storage(heap_allocator(T) *const this, size_t size) 125 80 { 126 81 enum { GROWTH_RATE = 2 };
Note:
See TracChangeset
for help on using the changeset viewer.