diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-05-18 18:54:23 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-05-18 18:54:23 -0300 |
| commit | 7fe30185df21617cf44100f89db462cd4501050e (patch) | |
| tree | bc22eb6b6104094814628e2084f51d0129f9d83d /src/vector.hh | |
| parent | 1378f2c7ddbdc0e5f3b1b9adc68b6e53eb3e5bfd (diff) | |
| download | game-7fe30185df21617cf44100f89db462cd4501050e.tar.gz game-7fe30185df21617cf44100f89db462cd4501050e.zip | |
implement `matrix` and move containers into their own directory
Diffstat (limited to 'src/vector.hh')
| -rw-r--r-- | src/vector.hh | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/src/vector.hh b/src/vector.hh deleted file mode 100644 index 044ffe1..0000000 --- a/src/vector.hh +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef TIBIA_VECTOR_HH_ -#define TIBIA_VECTOR_HH_ 1 - -#include "main.hh" - -// NOTE(fusion): What the actual fuck. This is an ever growing dynamic array -// with each access through `operator()` growing it to make sure the requested -// index is valid, even for negative indices. -template<typename T> -struct vector{ - // REGULAR FUNCTIONS - // ========================================================================= - vector(int min, int max, int block){ - int space = (max - min) + 1; - if(space < 1){ - error("vector: Ungueltige Feldgroesse %d bis %d.\n", min, max); - space = 1; - } - - if(block < 0){ - error("vector: Ungueltige Blockgroesse %d.\n", block); - block = 0; - } - - this->min = min; - this->max = max; - this->start = min; - this->space = space; - this->block = block; - this->initialized = false; - this->entry = new T[this->space]; - } - - vector(int min, int max, int block, T init) : vector(min, max, block) { - this->initialized = true; - this->init = init; - for(int i = 0; i < this->space; i += 1){ - this->entry[i] = init; - } - } - - // TODO(fusion): Probably missing some inlined destructor? - - T *at(int index){ - // TODO(fusion): This is probably not the best way to achieve this. - - while(index < this->start){ - int increment = this->block; - if(increment == 0){ - increment = this->space; - } - - T *entry = new T[this->space + increment]; - for(int i = this->min; i <= this->max; i += 1){ - int old_index = i - this->start; - int new_index = old_index + increment; - - // TODO(fusion): Do we actually need to swap elements here? I'm - // assuming some non-trivial structures that would invoke their - // destructors when `this->entry` gets deleted just below. - std::swap(entry[new_index], this->entry[old_index]); - } - - if(this->entry != NULL){ - delete[] this->entry; - } - this->entry = entry; - this->start -= increment; - this->space += increment; - } - - while(index >= (this->start + this->space)){ - int increment = this->block; - if(increment == 0){ - increment = this->space; - } - - T *entry = new[this->space + increment]; - for(int i = this->min; i <= this->max; i += 1){ - int old_index = i - this->start; - int new_index = old_index; - - // TODO(fusion): Same as above. - std::swap(entry[new_index], this->entry[old_index]); - } - - if(this->entry != NULL){ - delete[] this->entry; - } - this->entry = entry; - this->space += increment; - } - - while(index < this->min){ - this->min -= 1; - if(this->initialized){ - this->entry[this->min - this->start] = this->init; - } - } - - while(index > this->max){ - this->max += 1; - if(this->initialized){ - this->entry[this->max - this->start] = this->init; - } - } - - return &this->entry[index - this->start]; - } - - // DATA - // ========================================================================= - int min; - int max; - int start; - int space; - int block; - bool initialized; - T init; - T *entry; -}; - -#endif //TIBIA_VECTOR_HH_ |
