diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-06-15 17:35:06 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-06-15 17:35:06 -0300 |
| commit | 3cc587ab8df80d42d9dab1a73a37701f565a3499 (patch) | |
| tree | ea10cae94a9ef7a3c9b4080746a9697287e8991b /src/containers.hh | |
| parent | 33464579f6b8b079597617593d2bb733e982db8f (diff) | |
| download | game-3cc587ab8df80d42d9dab1a73a37701f565a3499.tar.gz game-3cc587ab8df80d42d9dab1a73a37701f565a3499.zip | |
more work on `operate.cc`
Diffstat (limited to 'src/containers.hh')
| -rw-r--r-- | src/containers.hh | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/containers.hh b/src/containers.hh index 85dcfde..f82159b 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -118,6 +118,14 @@ struct vector{ return &this->entry[index - this->start]; } + T copyAt(int index) const { + T Result = {}; + if(index >= this->start && index < (this->start + this->space)){ + Result = this->entry[index - this->start]; + } + return Result; + } + // DATA // ================= int min; @@ -466,7 +474,7 @@ struct fifo{ // TODO(fusion): We don't consider integer overflow at all. this->Head += 1; - return this->Entry[this->Head % this->Size]; + return &this->Entry[this->Head % this->Size]; } void remove(void){ @@ -478,6 +486,33 @@ struct fifo{ this->Tail += 1; } + int iterFirst(void){ + return this->Head; + } + + int iterLast(void){ + return this->Tail; + } + + T *iterNext(int *Position){ + if(*Position < this->Tail || this->Head < *Position){ + return NULL; + } + T *Result = &this->Entry[*Position % this->Size]; + *Position -= 1; + return Result; + } + + T *iterPrev(int *Position){ + if(*Position < this->Tail || this->Head < *Position){ + return NULL; + } + + T *Result = &this->Entry[*Position % this->Size]; + *Position += 1; + return Result; + } + // TODO(fusion): There is also a `fifoIterator` used a few times and it is // essentially iterating from `this->Head` towards `this->Tail`. All its // functions were inlined so I'm not sure it is needed. |
