Apply formating to all files. CLeanup
This commit is contained in:
parent
43e374f269
commit
744c01c5d0
928 changed files with 14515 additions and 21480 deletions
|
|
@ -5,20 +5,27 @@
|
|||
|
||||
namespace tp {
|
||||
|
||||
template<ualni tScale = 2>
|
||||
inline ualni BufferResizeScaling(ualni const size) { return size * tScale; }
|
||||
template <ualni tScale = 2>
|
||||
inline ualni BufferResizeScaling(const ualni size) {
|
||||
return size * tScale;
|
||||
}
|
||||
|
||||
template<ualni tScale = 2>
|
||||
inline ualni BufferResizeScalingDown(ualni const size) { return size / tScale; }
|
||||
template <ualni tScale = 2>
|
||||
inline ualni BufferResizeScalingDown(const ualni size) {
|
||||
return size / tScale;
|
||||
}
|
||||
|
||||
template<ualni tAddition = 1>
|
||||
inline ualni BufferResizeAddition(ualni const size) { return size + tAddition; }
|
||||
template <ualni tAddition = 1>
|
||||
inline ualni BufferResizeAddition(const ualni size) {
|
||||
return size + tAddition;
|
||||
}
|
||||
|
||||
template<ualni tAddition = 1>
|
||||
inline ualni BufferResizeAdditionDown(ualni const size) { return size - tAddition; }
|
||||
template <ualni tAddition = 1>
|
||||
inline ualni BufferResizeAdditionDown(const ualni size) {
|
||||
return size - tAddition;
|
||||
}
|
||||
|
||||
|
||||
template<typename tType, ualni tSize>
|
||||
template <typename tType, ualni tSize>
|
||||
class ConstSizeBuffer {
|
||||
typedef SelectValueOrReference<tType> Arg;
|
||||
|
||||
|
|
@ -37,6 +44,7 @@ namespace tp {
|
|||
|
||||
public:
|
||||
[[nodiscard]] ualni size() const { return mLoad; }
|
||||
|
||||
[[nodiscard]] ualni getBuffSize() const { return tSize; }
|
||||
|
||||
tType& first() {
|
||||
|
|
@ -94,28 +102,32 @@ namespace tp {
|
|||
}
|
||||
|
||||
public:
|
||||
|
||||
class IteratorPointer {
|
||||
protected:
|
||||
tType* mIter;
|
||||
|
||||
public:
|
||||
IteratorPointer() = default;
|
||||
|
||||
tType& operator->() { return *mIter; }
|
||||
|
||||
const tType& operator->() const { return *mIter; }
|
||||
};
|
||||
|
||||
class IteratorReference {
|
||||
protected:
|
||||
tType* mIter;
|
||||
|
||||
public:
|
||||
IteratorReference() = default;
|
||||
|
||||
tType* operator->() { return mIter; }
|
||||
|
||||
const tType* operator->() const { return mIter; }
|
||||
};
|
||||
|
||||
class Iterator : public TypeSelect<TypeTraits<tType>::isPointer, IteratorPointer, IteratorReference>::Result {
|
||||
public:
|
||||
|
||||
explicit Iterator(tType* iter) { this->mIter = iter; }
|
||||
|
||||
const Iterator& operator*() const { return *this; }
|
||||
|
|
@ -126,19 +138,16 @@ namespace tp {
|
|||
}
|
||||
|
||||
bool operator==(const Iterator& left) const { return left.mIter == this->mIter; }
|
||||
|
||||
bool operator!=(const Iterator& left) const { return left.mIter != this->mIter; }
|
||||
};
|
||||
|
||||
[[nodiscard]] Iterator begin() const {
|
||||
return Iterator(mBuff);
|
||||
}
|
||||
[[nodiscard]] Iterator begin() const { return Iterator(mBuff); }
|
||||
|
||||
[[nodiscard]] Iterator end() const {
|
||||
return Iterator(mBuff + mLoad);
|
||||
}
|
||||
[[nodiscard]] Iterator end() const { return Iterator(mBuff + mLoad); }
|
||||
|
||||
public:
|
||||
template<class tArchiver>
|
||||
template <class tArchiver>
|
||||
void archiveWrite(tArchiver& ar) const {
|
||||
ar << mLoad;
|
||||
for (auto item : *this) {
|
||||
|
|
@ -146,7 +155,7 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
template<class tArchiver>
|
||||
template <class tArchiver>
|
||||
void archiveRead(tArchiver& ar) {
|
||||
clear();
|
||||
ar >> mLoad;
|
||||
|
|
@ -156,13 +165,7 @@ namespace tp {
|
|||
}
|
||||
};
|
||||
|
||||
template<
|
||||
typename tType,
|
||||
class tAllocator = DefaultAllocator,
|
||||
ualni (tResizePolicy)(ualni) = BufferResizeScaling<2>,
|
||||
ualni (tResizePolicyDown)(ualni) = BufferResizeScalingDown<2>,
|
||||
ualni tMinSize = 4
|
||||
>
|
||||
template <typename tType, class tAllocator = DefaultAllocator, ualni(tResizePolicy)(ualni) = BufferResizeScaling<2>, ualni(tResizePolicyDown)(ualni) = BufferResizeScalingDown<2>, ualni tMinSize = 4>
|
||||
class Buffer {
|
||||
typedef SelectValueOrReference<tType> Arg;
|
||||
|
||||
|
|
@ -173,17 +176,25 @@ namespace tp {
|
|||
ualni mLoad;
|
||||
|
||||
public:
|
||||
Buffer() : mSize(tMinSize), mLoad(0) {
|
||||
Buffer() :
|
||||
mSize(tMinSize),
|
||||
mLoad(0) {
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * tMinSize);
|
||||
}
|
||||
|
||||
explicit Buffer(ualni size) : mSize(size), mLoad(0) {
|
||||
explicit Buffer(ualni size) :
|
||||
mSize(size),
|
||||
mLoad(0) {
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * size);
|
||||
}
|
||||
|
||||
Buffer(const Buffer& in) : mSize(in.mSize), mLoad(in.mLoad) {
|
||||
Buffer(const Buffer& in) :
|
||||
mSize(in.mSize),
|
||||
mLoad(in.mLoad) {
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * mSize);
|
||||
for (ualni i = 0; i < mLoad; i++) new (&mBuff[i]) tType(in.mBuff[i]);
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
new (&mBuff[i]) tType(in.mBuff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
|
|
@ -192,44 +203,48 @@ namespace tp {
|
|||
}
|
||||
|
||||
Buffer& operator=(const Buffer& in) {
|
||||
if (this == &in) return *this;
|
||||
if (this == &in) {
|
||||
return *this;
|
||||
}
|
||||
this->~Buffer();
|
||||
new (this) Buffer(in);
|
||||
return *this;
|
||||
new (this) Buffer(in);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Buffer() {
|
||||
for (ualni i = 0; i < mLoad; i++) mBuff[i].~tType();
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
mBuff[i].~tType();
|
||||
}
|
||||
mAllocator.deallocate(mBuff);
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] ualni size() const {
|
||||
return mLoad;
|
||||
}
|
||||
[[nodiscard]] ualni size() const { return mLoad; }
|
||||
|
||||
[[nodiscard]] ualni getBuffSize() const { return mSize; }
|
||||
|
||||
[[nodiscard]] const tType* getBuff() const { return mBuff; }
|
||||
|
||||
[[nodiscard]] tType* getBuff() { return mBuff; }
|
||||
|
||||
[[nodiscard]] ualni getBuffSize() const {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
tType& first() {
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return *mBuff;
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return *mBuff;
|
||||
}
|
||||
|
||||
const tType& first() const {
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return *mBuff;
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return *mBuff;
|
||||
}
|
||||
|
||||
tType& last() {
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return mBuff[mLoad - 1];
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return mBuff[mLoad - 1];
|
||||
}
|
||||
|
||||
const tType& last() const {
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return mBuff[mLoad - 1];
|
||||
DEBUG_ASSERT(mLoad)
|
||||
return mBuff[mLoad - 1];
|
||||
}
|
||||
|
||||
tType& operator[](ualni idx) {
|
||||
|
|
@ -244,10 +259,16 @@ namespace tp {
|
|||
|
||||
public:
|
||||
bool operator==(const Buffer& in) const {
|
||||
if (this == &in) return true;
|
||||
if (mLoad != in.mLoad) return false;
|
||||
if (this == &in) {
|
||||
return true;
|
||||
}
|
||||
if (mLoad != in.mLoad) {
|
||||
return false;
|
||||
}
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
if (mBuff[i] != in.mBuff[i]) return false;
|
||||
if (mBuff[i] != in.mBuff[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -262,67 +283,86 @@ namespace tp {
|
|||
}
|
||||
|
||||
void append(Arg data) {
|
||||
if (mLoad == mSize) resizeBuffer(tResizePolicy(mSize));
|
||||
if (mLoad == mSize) {
|
||||
resizeBuffer(tResizePolicy(mSize));
|
||||
}
|
||||
new (&mBuff[mLoad]) tType(data);
|
||||
mLoad++;
|
||||
}
|
||||
|
||||
void append(const Buffer& in) {
|
||||
if (!in.mLoad) return;
|
||||
auto newLoad = mLoad + in.mLoad;
|
||||
auto newSize = mSize;
|
||||
while (newLoad >= newSize) newSize = tResizePolicy(newSize);
|
||||
if (newSize != mSize) resizeBuffer(newSize);
|
||||
for (auto i = mLoad; i < newLoad; i++) new (&mBuff[i]) tType(in.mBuff[i - mLoad]);
|
||||
mLoad = newLoad;
|
||||
}
|
||||
void append(const Buffer& in) {
|
||||
if (!in.mLoad) {
|
||||
return;
|
||||
}
|
||||
auto newLoad = mLoad + in.mLoad;
|
||||
auto newSize = mSize;
|
||||
while (newLoad >= newSize) {
|
||||
newSize = tResizePolicy(newSize);
|
||||
}
|
||||
if (newSize != mSize) {
|
||||
resizeBuffer(newSize);
|
||||
}
|
||||
for (auto i = mLoad; i < newLoad; i++) {
|
||||
new (&mBuff[i]) tType(in.mBuff[i - mLoad]);
|
||||
}
|
||||
mLoad = newLoad;
|
||||
}
|
||||
|
||||
void pop() {
|
||||
DEBUG_ASSERT(mLoad)
|
||||
mBuff[mLoad].~tType();
|
||||
mLoad--;
|
||||
ualni prevSize = tResizePolicyDown(mSize);
|
||||
DEBUG_ASSERT(prevSize < mSize)
|
||||
if (prevSize > mLoad) resizeBuffer(prevSize);
|
||||
DEBUG_ASSERT(prevSize < mSize)
|
||||
if (prevSize > mLoad) {
|
||||
resizeBuffer(prevSize);
|
||||
}
|
||||
}
|
||||
|
||||
void reserve(ualni aSize) {
|
||||
for (ualni i = 0; i < mLoad; i++) mBuff[i].~tType();
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
mBuff[i].~tType();
|
||||
}
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * aSize);
|
||||
mSize = aSize;
|
||||
mLoad = aSize;
|
||||
for (ualni i = 0; i < mLoad; i++) new (mBuff + i) tType();
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
new (mBuff + i) tType();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
class IteratorPointer {
|
||||
protected:
|
||||
tType* mIter;
|
||||
|
||||
public:
|
||||
IteratorPointer() = default;
|
||||
|
||||
tType& operator->() { return *mIter; }
|
||||
|
||||
const tType& operator->() const { return *mIter; }
|
||||
};
|
||||
|
||||
class IteratorReference {
|
||||
protected:
|
||||
tType* mIter;
|
||||
|
||||
public:
|
||||
IteratorReference() = default;
|
||||
|
||||
tType* operator->() { return mIter; }
|
||||
|
||||
const tType* operator->() const { return mIter; }
|
||||
};
|
||||
|
||||
class Iterator : public TypeSelect<TypeTraits<tType>::isPointer, IteratorPointer, IteratorReference>::Result {
|
||||
public:
|
||||
|
||||
explicit Iterator(tType* iter) { this->mIter = iter; }
|
||||
|
||||
const Iterator& operator*() const { return *this; }
|
||||
|
||||
tType& data() {
|
||||
return *this->mIter;
|
||||
}
|
||||
tType& data() { return *this->mIter; }
|
||||
|
||||
Iterator& operator++() {
|
||||
this->mIter++;
|
||||
|
|
@ -330,20 +370,16 @@ namespace tp {
|
|||
}
|
||||
|
||||
bool operator==(const Iterator& left) const { return left.mIter == this->mIter; }
|
||||
|
||||
bool operator!=(const Iterator& left) const { return left.mIter != this->mIter; }
|
||||
};
|
||||
|
||||
[[nodiscard]] Iterator begin() const {
|
||||
return Iterator(mBuff);
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator end() const {
|
||||
return Iterator(mBuff + mLoad);
|
||||
}
|
||||
[[nodiscard]] Iterator begin() const { return Iterator(mBuff); }
|
||||
|
||||
[[nodiscard]] Iterator end() const { return Iterator(mBuff + mLoad); }
|
||||
|
||||
public:
|
||||
template<class tArchiver>
|
||||
template <class tArchiver>
|
||||
void archiveWrite(tArchiver& ar) const {
|
||||
ar << mLoad;
|
||||
for (auto item : *this) {
|
||||
|
|
@ -351,45 +387,56 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
template<class tArchiver>
|
||||
template <class tArchiver>
|
||||
void archiveRead(tArchiver& ar) {
|
||||
clear();
|
||||
decltype(mLoad) len;
|
||||
ar >> len;
|
||||
for (auto i = len; i; i--) {
|
||||
// TODO : optimize
|
||||
if (mLoad == mSize) resizeBuffer(tResizePolicy(mSize));
|
||||
if (mLoad == mSize) {
|
||||
resizeBuffer(tResizePolicy(mSize));
|
||||
}
|
||||
ar >> mBuff[mLoad];
|
||||
mLoad++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void resizeBuffer(ualni newSize) {
|
||||
DEBUG_ASSERT(newSize >= mLoad)
|
||||
auto const oldBuff = mBuff;
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * newSize);
|
||||
for (ualni i = 0; i < mLoad; i++) new (&mBuff[i]) tType(oldBuff[i]);
|
||||
for (ualni i = 0; i < mLoad; i++) oldBuff[i].~tType();
|
||||
mAllocator.deallocate(oldBuff);
|
||||
mSize = newSize;
|
||||
}
|
||||
private:
|
||||
void resizeBuffer(ualni newSize) {
|
||||
DEBUG_ASSERT(newSize >= mLoad)
|
||||
const auto oldBuff = mBuff;
|
||||
mBuff = (tType*) mAllocator.allocate(sizeof(tType) * newSize);
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
new (&mBuff[i]) tType(oldBuff[i]);
|
||||
}
|
||||
for (ualni i = 0; i < mLoad; i++) {
|
||||
oldBuff[i].~tType();
|
||||
}
|
||||
mAllocator.deallocate(oldBuff);
|
||||
mSize = newSize;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename tType>
|
||||
template <typename tType>
|
||||
void generatePermutations(const Buffer<Buffer<tType>>& in, Buffer<Buffer<tType>>& out) {
|
||||
typedef long long Idx;
|
||||
|
||||
// sanity check
|
||||
for (const auto & vec : in) {
|
||||
if (!vec.size()) return;
|
||||
for (const auto& vec : in) {
|
||||
if (!vec.size()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
out.resize(in.size());
|
||||
auto len = Idx(1);
|
||||
for (const auto & vec : in) len *= (Idx) vec.size();
|
||||
for (auto i = 0; i < in.size(); i++) out[i].resize(len);
|
||||
for (const auto& vec : in) {
|
||||
len *= (Idx) vec.size();
|
||||
}
|
||||
for (auto i = 0; i < in.size(); i++) {
|
||||
out[i].resize(len);
|
||||
}
|
||||
|
||||
auto dub = Idx(1);
|
||||
for (auto power = (Idx) in.size() - 1; power >= 0; power--) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue