增加IndexedListTest.cpp测试其迭代器
This commit is contained in:
parent
48243fc350
commit
0ba4eb4919
@ -66,6 +66,7 @@ cm_example_project("DataType/Collection" StackTest datatype/collection/Sta
|
|||||||
cm_example_project("DataType/Collection" QueueTest datatype/collection/QueueTest.cpp)
|
cm_example_project("DataType/Collection" QueueTest datatype/collection/QueueTest.cpp)
|
||||||
cm_example_project("DataType/Collection" PoolTest datatype/collection/PoolTest.cpp)
|
cm_example_project("DataType/Collection" PoolTest datatype/collection/PoolTest.cpp)
|
||||||
cm_example_project("DataType/Collection" ListTest datatype/collection/ListTest.cpp)
|
cm_example_project("DataType/Collection" ListTest datatype/collection/ListTest.cpp)
|
||||||
|
cm_example_project("DataType/Collection" IndexedListTest datatype/collection/IndexedListTest.cpp)
|
||||||
cm_example_project("DataType/Collection" MapTest datatype/collection/MapTest.cpp)
|
cm_example_project("DataType/Collection" MapTest datatype/collection/MapTest.cpp)
|
||||||
cm_example_project("DataType/Collection" MultiMapTest datatype/collection/MultiMapTest.cpp)
|
cm_example_project("DataType/Collection" MultiMapTest datatype/collection/MultiMapTest.cpp)
|
||||||
cm_example_project("DataType/Collection" StackPoolTest datatype/collection/StackPoolTest.cpp)
|
cm_example_project("DataType/Collection" StackPoolTest datatype/collection/StackPoolTest.cpp)
|
||||||
|
71
datatype/collection/IndexedListTest.cpp
Normal file
71
datatype/collection/IndexedListTest.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include<hgl/type/IndexedList.h>
|
||||||
|
#include<random>
|
||||||
|
#include<iostream>
|
||||||
|
#include<iomanip>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void out_list(const char *type,const DataArray<T> &da)
|
||||||
|
{
|
||||||
|
const T *p=da.GetData();
|
||||||
|
|
||||||
|
std::cout<<type<<"[";
|
||||||
|
|
||||||
|
for(int32 i=0;i<da.GetCount();i++)
|
||||||
|
{
|
||||||
|
if(i>0)
|
||||||
|
std::cout<<",";
|
||||||
|
|
||||||
|
std::cout<<*p;
|
||||||
|
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
void out_list(const char *info,const IndexedList<int> &il)
|
||||||
|
{
|
||||||
|
const int32 count=il.GetCount();
|
||||||
|
|
||||||
|
std::cout<<info;
|
||||||
|
|
||||||
|
out_list(" Index",il.GetRawIndex());
|
||||||
|
out_list(" RawData",il.GetRawData());
|
||||||
|
|
||||||
|
{
|
||||||
|
std::cout<<" IL[";
|
||||||
|
|
||||||
|
for(auto it:il)
|
||||||
|
{
|
||||||
|
std::cout<<" "<<it;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int,char **)
|
||||||
|
{
|
||||||
|
std::random_device device;
|
||||||
|
std::mt19937 generator(device());
|
||||||
|
|
||||||
|
IndexedList<int> il;
|
||||||
|
|
||||||
|
for(int i=0;i<10;i++)
|
||||||
|
il.Add(generator()%100);
|
||||||
|
|
||||||
|
out_list("origin",il);
|
||||||
|
|
||||||
|
for(int i=0;i<5;i++)
|
||||||
|
{
|
||||||
|
int pos=generator()%il.GetCount();
|
||||||
|
|
||||||
|
std::cout<<"Delete "<<pos<<std::endl;
|
||||||
|
il.Delete(pos);
|
||||||
|
out_list("delete",il);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
template<typename KEY,typename VALUE>
|
|
||||||
struct DataPair
|
|
||||||
{
|
|
||||||
KEY key;
|
|
||||||
VALUE value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename KEY,typename VALUE>
|
|
||||||
class UnorderedMap
|
|
||||||
{
|
|
||||||
ObjectList<DataPair<KEY,VALUE>> data_list;
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user