added Uint2HexStrTest.cpp and MapTest.cpp
This commit is contained in:
parent
f2cf3f5db4
commit
c29f25daeb
@ -30,6 +30,9 @@ cm_example_project("DataType" SplitStringTest)
|
||||
add_executable(StrChrTest datatype/strchr_test.cpp)
|
||||
cm_example_project("DataType" StrChrTest)
|
||||
|
||||
add_executable(MapTest datatype/MapTest.cpp)
|
||||
cm_example_project("DataType" MapTest)
|
||||
|
||||
add_executable(MultiMapTest datatype/MultiMapTest.cpp)
|
||||
cm_example_project("DataType" MultiMapTest)
|
||||
|
||||
@ -46,6 +49,9 @@ cm_example_project("DataType" Size2Test)
|
||||
add_executable(DataArrayTest datatype/DataArrayTest.cpp)
|
||||
cm_example_project("DataType" DataArrayTest)
|
||||
|
||||
add_executable(Uint2HexStrTest datatype/Uint2HexStrTest.cpp)
|
||||
cm_example_project("DataType" Uint2HexStrTest)
|
||||
|
||||
####################################################################################################
|
||||
|
||||
add_executable(FixFilenameTest filesystem/FixFilenameTest.cpp)
|
||||
|
74
datatype/MapTest.cpp
Normal file
74
datatype/MapTest.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include<iostream>
|
||||
#include<stdlib.h>
|
||||
#include<time.h>
|
||||
#include<hgl/type/SortedSets.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace std;
|
||||
|
||||
void out_id(Map<int,int> &int_map)
|
||||
{
|
||||
const int count=int_map.GetCount();
|
||||
|
||||
cout<<"count:"<<count<<" ";
|
||||
|
||||
//传统用法
|
||||
// Pair<int,int> **p=int_map.GetDataList();
|
||||
|
||||
// for(int i=0;i<count;i++)
|
||||
// {
|
||||
// cout<<"["<</*i<<":"<<*/(*p)->left<<","<<(*p)->right<<"]";
|
||||
// ++p;
|
||||
// }
|
||||
|
||||
//lambda用法
|
||||
int_map.Enum([](const int &key,int value)
|
||||
{
|
||||
cout<<"["<<key<<","<<value<<"]";
|
||||
});
|
||||
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
int index;
|
||||
int value;
|
||||
SortedSets<int> int_sets;
|
||||
Map<int,int> int_map;
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
index=rand()%20;
|
||||
if(!int_sets.IsMember(index))break;
|
||||
}
|
||||
|
||||
int_sets.Add(index);
|
||||
|
||||
value=rand()%255;
|
||||
|
||||
cout<<"add index="<<index<<" value="<<value<<endl;
|
||||
int_map.Add(index,value);
|
||||
|
||||
out_id(int_map);
|
||||
}
|
||||
|
||||
cout<<endl;
|
||||
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
value=rand()%255;
|
||||
|
||||
cout<<"update index="<<i<<" value="<<value<<endl;
|
||||
int_map.Change(i,value);
|
||||
|
||||
out_id(int_map);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
18
datatype/Uint2HexStrTest.cpp
Normal file
18
datatype/Uint2HexStrTest.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include<iostream>
|
||||
#include<hgl/type/StrChar.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
char str[32];
|
||||
uint8 a=0x80;
|
||||
uint16 b=0x4567;
|
||||
|
||||
htos(str,32,a ); std::cout<<"to uint : 0x"<<str<<std::endl;
|
||||
htos(str,32,b ); std::cout<<"to uint : 0x"<<str<<std::endl;
|
||||
htos(str,32,str ); std::cout<<"str to uint : 0x"<<str<<std::endl;
|
||||
htos(str,32,main); std::cout<<"main to uint : 0x"<<str<<std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user