mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-12-17 07:37:02 +00:00
Add all the files
This commit is contained in:
parent
e3db07a16a
commit
d60742f52b
1445 changed files with 430238 additions and 0 deletions
74
src/util/helpers/fixedSizeList.h
Normal file
74
src/util/helpers/fixedSizeList.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include<array>
|
||||
|
||||
template<typename T, uint32 maxElements, bool checkMaxSize = true>
|
||||
class FixedSizeList
|
||||
{
|
||||
public:
|
||||
std::array<T, maxElements> m_elementArray;
|
||||
int count = 0;
|
||||
|
||||
void add(T n)
|
||||
{
|
||||
if (checkMaxSize && count >= maxElements)
|
||||
return;
|
||||
m_elementArray[count] = n;
|
||||
count++;
|
||||
}
|
||||
|
||||
void addUnique(T n)
|
||||
{
|
||||
if (checkMaxSize && count >= maxElements)
|
||||
return;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_elementArray[i] == n)
|
||||
return;
|
||||
}
|
||||
m_elementArray[count] = n;
|
||||
count++;
|
||||
}
|
||||
|
||||
void remove(T n)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_elementArray[i] == n)
|
||||
{
|
||||
m_elementArray[i] = m_elementArray[count - 1];
|
||||
count--;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool containsAndRemove(T n)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_elementArray[i] == n)
|
||||
{
|
||||
m_elementArray[i] = m_elementArray[count - 1];
|
||||
count--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
sint32 find(T n)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (m_elementArray[i] == n)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue