17#if (__cplusplus >= 201703L ) || (_MSVC_LANG >= 201703L)
18#define IFCONSTEXPR if constexpr
77 typename std::enable_if<std::is_trivially_destructible<X>::value ==
false>::type
85 typename std::enable_if<std::is_trivially_destructible<X>::value ==
true>::type
93 typename std::enable_if<std::is_trivially_destructible<X>::value ==
false>::type
104 typename std::enable_if<std::is_trivially_destructible<X>::value ==
true>::type
147 this->data =
nullptr;
162 this->
data[i] = rhs[i];
175 capacity(rhs.capacity),
194 this->Reserve(rhs.
size);
197 this->data[i] = rhs[i];
199 this->size = rhs.
size;
200 this->grow = rhs.
grow;
214 this->data = rhs.data;
215 this->size = rhs.size;
216 this->grow = rhs.grow;
217 this->capacity = rhs.capacity;
218 this->start = rhs.start;
233 return this->data[MapIndex(index)];
243 if(this->size != rhs.
size)
return false;
245 for(
IndexT i= 0; i < this->size; i++)
247 if(!((*
this)[i] == rhs[i] ))
272 for(
IndexT i = 0 ; i<this->size; i++)
274 if (this->
operator[](i) == e)
295 IndexT idx = this->MapIndex(i);
297 this->DestroyElement<TYPE>(idx);
300 if (idx < this->start)
302 for (
IndexT j = 0; j < this->size - i; ++j)
304 this->data[idx] = this->data[idx+1];
310 for (
IndexT j = 0; j < i; j++)
312 this->data[idx] = this->data[idx-1];
315 this->start = this->MapIndex(1);
328 this->ClearAll<TYPE>();
340 if (num > this->capacity)
345 TYPE * newdata =
new TYPE[num];
348 if (this->capacity > 0)
355 SizeT upper = this->capacity - this->start;
356 SizeT lower = this->size - (this->capacity - this->start);
360 Memory::Copy(&this->data[this->start], newdata, this->size *
sizeof(TYPE));
364 Memory::Copy(&this->data[this->start], newdata, upper *
sizeof(TYPE));
365 Memory::Copy(this->data, &newdata[upper], lower *
sizeof(TYPE));
368 if (this->data !=
nullptr)
375 for (
IndexT i = 0; i < this->size; i++)
377 IndexT idx = this->MapIndex(i);
378 newdata[i] = std::move(this->data[idx]);
379 this->DestroyElement<TYPE>(idx);
381 if (this->data !=
nullptr)
387 this->data = newdata;
388 this->capacity = num;
396template<
class TYPE>
void
400 if (0 == this->capacity)
402 growToSize = this->grow;
407 SizeT growBy = this->capacity >> 1;
411 growBy = MinGrowSize;
413 else if (growBy > MaxGrowSize)
415 growBy = MaxGrowSize;
417 growToSize = this->capacity + growBy;
419 this->Reserve(growToSize);
441 return this->capacity;
452 return this->size == 0;
463 if (this->size == this->capacity)
467 this->data[this->MapIndex(this->size++)] = e;
478 if (this->size == this->capacity)
483 this->data[this->MapIndex(this->size++)]= std::move(e);
496 TYPE t = this->data[this->start];
497 #if __cplusplus > 201703L
498 if constexpr (!std::is_nothrow_destructible_v<TYPE>)
500 (&(this->data[this->start]))->~TYPE();
503 this->DestroyElement<TYPE>(this->start);
505 this->start = this->MapIndex(1);
519 return this->data[this->start];
533 idx = (idx + this->start) % this->capacity;
540 return (idx + this->capacity) % this->capacity;
Nebula's queue class (a FIFO container).
Definition queue.h:28
Queue(Queue< TYPE > &&rhs)
move constructor
Definition queue.h:173
void Enqueue(const TYPE &e)
add element to the back of the Dequeue, can trigger grow
Definition queue.h:461
bool Contains(const TYPE &e) const
return true if Dequeue contains element
Definition queue.h:270
void Enqueue(TYPE &&e)
Definition queue.h:476
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type DestroyElement(IndexT idx)
Definition queue.h:86
static const SizeT MinGrowSize
Definition queue.h:114
SizeT capacity
Definition queue.h:119
bool operator!=(const Queue< TYPE > &rhs) const
inequality operator
Definition queue.h:260
bool operator==(const Queue< TYPE > &rhs) const
equality operator
Definition queue.h:241
SizeT size
Definition queue.h:118
void Clear()
remove all elements from the Dequeue
Definition queue.h:326
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type ClearAll()
Definition queue.h:105
void Grow()
grow Dequeue by internal growing rules (slow)
Definition queue.h:397
~Queue()
destructor
Definition queue.h:140
void operator=(Queue< TYPE > &&rhs)
move assignment operator
Definition queue.h:210
Queue()
constructor
Definition queue.h:126
Queue(const Queue< TYPE > &rhs)
copy constructor
Definition queue.h:155
SizeT Capacity() const
returns allocation of elements in the Dequeue
Definition queue.h:439
void EraseIndex(const IndexT i)
erase element at index (slow!!)
bool IsEmpty() const
return true if Dequeue is empty
Definition queue.h:450
TYPE * data
Definition queue.h:112
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type DestroyElement(IndexT idx)
Definition queue.h:78
void operator=(const Queue< TYPE > &rhs)
assignment operator
Definition queue.h:190
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type ClearAll()
Definition queue.h:94
SizeT grow
Definition queue.h:116
static const SizeT MaxGrowSize
Definition queue.h:115
void Reserve(SizeT num)
increase capacity to fit N more elements into the Dequeue (slow)
Definition queue.h:338
TYPE & Peek() const
access to element at front of Dequeue without removing it
Definition queue.h:516
SizeT start
Definition queue.h:117
TYPE Dequeue()
remove the element from the front of the Dequeue
Definition queue.h:492
IndexT MapIndex(IndexT index) const
maps index to actual item position using wrapping
Definition queue.h:531
TYPE & operator[](IndexT index) const
access element by index, 0 is the frontmost element (next to be dequeued)
Definition queue.h:230
SizeT Size() const
returns number of elements in the Dequeue
Definition queue.h:428
static uint RoundUp(uint val, uint boundary)
generic roundup
Definition round.h:83
#define n_assert(exp)
Definition debug.h:50
void Copy(const void *from, void *to, size_t numBytes)
Copy a chunk of memory (note the argument order is different from memcpy()!!!)
Definition osxmemory.cc:213
Math::float2 size
Definition histogramcontext.cc:36
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
bool operator==(const String &a, const String &b)
Definition string.cc:830
#define IFCONSTEXPR
Definition queue.h:20
Nebula's scalar datatype.
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48