Containers New Features
This commit is contained in:
parent
ec2a71ccdb
commit
72a25600a2
10 changed files with 1192 additions and 0 deletions
89
Containers/outdated/tests/fat_nodes.cpp
Normal file
89
Containers/outdated/tests/fat_nodes.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
#include "containers.h"
|
||||
|
||||
namespace tp {
|
||||
|
||||
struct AvlNode {
|
||||
|
||||
template<typename Type>
|
||||
struct EphemeralNode {
|
||||
Type mVal = NULL;
|
||||
halni mVersion = NULL;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
struct EphemeralsContainer {
|
||||
List<EphemeralNode<Type>> mList;
|
||||
};
|
||||
|
||||
struct PesistentLink {
|
||||
static EphemeralsContainer<AvlNode*> sContainer;
|
||||
EphemeralNode<AvlNode*>* mNode = NULL;
|
||||
PesistentLink& operator=(const PesistentLink& field) {
|
||||
}
|
||||
PesistentLink& operator=(AvlNode* val) {
|
||||
}
|
||||
//Type& operator->() { return mNode->mVal; }
|
||||
//const ListIterator& operator*() { return *this; }
|
||||
operator AvlNode*() {
|
||||
}
|
||||
};
|
||||
|
||||
struct PesistentValue {
|
||||
static EphemeralsContainer<halni> sContainer;
|
||||
EphemeralNode<halni>* mNode = NULL;
|
||||
PesistentLink& operator=(const PesistentLink& field) {}
|
||||
PesistentLink& operator=(halni val) {}
|
||||
operator halni() {
|
||||
}
|
||||
};
|
||||
|
||||
PesistentLink mLeft;
|
||||
PesistentLink mRight;
|
||||
PesistentLink mParent;
|
||||
PesistentValue mHeight;
|
||||
|
||||
PesistentValue mVal;
|
||||
halni mRefCount = 0;
|
||||
|
||||
AvlNode() { mVal = 0; }
|
||||
AvlNode(halni aKey) {
|
||||
mVal = aKey;
|
||||
}
|
||||
|
||||
bool disentRight(halni aKey) {
|
||||
return aKey > mVal;
|
||||
}
|
||||
|
||||
bool disentLeft(halni aKey) {
|
||||
return aKey < mVal;
|
||||
}
|
||||
|
||||
bool exactNode(halni aKey) {
|
||||
return aKey == mVal;
|
||||
}
|
||||
|
||||
halni getFindKey(AvlNode* node = NULL) {
|
||||
return mVal;
|
||||
}
|
||||
|
||||
void copyData(const AvlNode& in) {
|
||||
mVal = in.mVal;
|
||||
}
|
||||
|
||||
halni keyInRightSubtree(halni key) { return key; }
|
||||
halni keyInLeftSubtree(halni key) { return key; }
|
||||
|
||||
void updateTreeCahceCallBack() {}
|
||||
|
||||
void* operator new(std::size_t) {
|
||||
}
|
||||
|
||||
void operator delete(void* p) {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
void fat_nodes_test() {
|
||||
tp::AvlTree<tp::AvlNode, tp::halni> avl;
|
||||
}
|
||||
148
Containers/outdated/tests/quick.cpp
Normal file
148
Containers/outdated/tests/quick.cpp
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
|
||||
#include "containers.h"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
void list_test() {
|
||||
tp::List<int> q;
|
||||
|
||||
q.pushBack(0);
|
||||
q.pushBack(1);
|
||||
q.pushBack(2);
|
||||
q.pushBack(3);
|
||||
q.pushBack(4);
|
||||
q.pushBack(5);
|
||||
|
||||
for (auto node : q) {
|
||||
printf("%i ", node.data());
|
||||
}
|
||||
|
||||
q.popBack();
|
||||
q.popFront();
|
||||
|
||||
q.pushBack(4);
|
||||
q.pushFront(1);
|
||||
|
||||
q.invert();
|
||||
|
||||
for (auto node : q) {
|
||||
printf("%i ", node.data());
|
||||
}
|
||||
|
||||
q.sort([](ListNode<int>* const& node1, ListNode<int>* const& node2) { return node1->data > node2->data; });
|
||||
|
||||
for (auto node : q) {
|
||||
printf("%i ", node.data());
|
||||
}
|
||||
}
|
||||
|
||||
// numeric node test
|
||||
void avl_test() {
|
||||
AvlTree<NumericNode<float>, float> avl;
|
||||
|
||||
for (auto i : Range<ualni>(100)) {
|
||||
//avl.insert(i, halnf(i));
|
||||
auto ret = avl.isInvalid(avl.head());
|
||||
DBG_BREAK(ret);
|
||||
}
|
||||
|
||||
for (auto node : avl) {
|
||||
printf("%f ", node.node()->mVal);
|
||||
}
|
||||
|
||||
auto p = avl.find(0);
|
||||
p = avl.find(50);
|
||||
//p = avl.find(avl_ts(100));
|
||||
|
||||
auto t = avl.find_less_or_eq(50);
|
||||
t = avl.find_less_or_eq(50.5);
|
||||
t = avl.find_less_or_eq(100.5);
|
||||
t = avl.find_less_or_eq(0.5);
|
||||
|
||||
auto end = avl.end(avl.find(99));
|
||||
for (auto iter = avl.begin(p); iter != end; ++iter) {
|
||||
printf("%f ", iter.node()->mVal);
|
||||
}
|
||||
}
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
void map_test() {
|
||||
|
||||
struct CheckData {
|
||||
ualni mDummy = 0;
|
||||
bool mAddedToMap = false;
|
||||
};
|
||||
|
||||
HashMap<alni, alni> map;
|
||||
|
||||
const uhalni test_scale = 1000;
|
||||
const uhalni test_iterations = 100000;
|
||||
|
||||
Array<CheckData> checker(test_scale);
|
||||
|
||||
for (auto test : Range<ualni>(test_iterations)) {
|
||||
auto idx = alni(tp::randf() * (test_scale - 1));
|
||||
|
||||
auto map_idx = map.presents(idx);
|
||||
if (checker[idx].mAddedToMap != map_idx) {
|
||||
DBG_BREAK("Presentment mismatch");
|
||||
}
|
||||
|
||||
if (map_idx) {
|
||||
if (idx != map.getSlotVal(map_idx)) {
|
||||
DBG_BREAK("Data mismatch");
|
||||
}
|
||||
}
|
||||
|
||||
if (checker[idx].mAddedToMap) {
|
||||
map.remove(idx);
|
||||
}
|
||||
else {
|
||||
map.put(idx, idx);
|
||||
}
|
||||
|
||||
checker[idx].mAddedToMap = !checker[idx].mAddedToMap;
|
||||
}
|
||||
|
||||
for (auto iter : map) {
|
||||
iter->val = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void queue_test() {
|
||||
tp::Queue<int> q;
|
||||
|
||||
q.push(0);
|
||||
q.push(1);
|
||||
q.push(2);
|
||||
q.push(3);
|
||||
q.push(4);
|
||||
q.push(5);
|
||||
|
||||
for (auto node : q) {
|
||||
printf("%i ", node.mIter->data);
|
||||
}
|
||||
|
||||
q.pop();
|
||||
q.pop();
|
||||
q.pop();
|
||||
q.pop();
|
||||
q.pop();
|
||||
q.pop();
|
||||
|
||||
q.push(3);
|
||||
q.push(4);
|
||||
q.push(5);
|
||||
|
||||
for (auto node : q) {
|
||||
printf("%i ", node.mIter->data);
|
||||
}
|
||||
}
|
||||
|
||||
void timeline_test() {
|
||||
tp::DebugTimeline<tp::halni> tl(100);
|
||||
tl.add(1);
|
||||
}
|
||||
16
Containers/outdated/tests/tests.cpp
Normal file
16
Containers/outdated/tests/tests.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
#include "containers.h"
|
||||
|
||||
void avl_test();
|
||||
void map_test();
|
||||
void queue_test();
|
||||
void list_test();
|
||||
void fat_nodes_test();
|
||||
|
||||
int main() {
|
||||
tp::alloc_init();
|
||||
|
||||
map_test();
|
||||
|
||||
tp::alloc_uninit();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue