mirror of
https://gitee.com/Lamdonn/varch.git
synced 2025-12-06 08:46:42 +08:00
472 lines
22 KiB
C
472 lines
22 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#if defined(TEST_TARGET_dict)
|
|
#include <varch/command.h>
|
|
#include <varch/unitt.h>
|
|
#include <varch/dict.h>
|
|
#else
|
|
#include "init.h"
|
|
#include "command.h"
|
|
#include "unitt.h"
|
|
#include "kern.h"
|
|
#include "dict.h"
|
|
#endif
|
|
|
|
/************************************************************************************/
|
|
/************************************* Unit Test ************************************/
|
|
/************************************************************************************/
|
|
|
|
// #define EXIT_TEST
|
|
extern uint64_t unitt_clock(void);
|
|
|
|
static int test_0(void)
|
|
{
|
|
for (int i = 0; i < 100; i++)
|
|
{
|
|
if (0)
|
|
{
|
|
|
|
#if defined (EXIT_TEST)
|
|
exit(0);
|
|
#endif
|
|
return UNITT_E_FAIL;
|
|
}
|
|
}
|
|
|
|
return UNITT_E_OK;
|
|
}
|
|
|
|
static void unitt_task(void)
|
|
{
|
|
static UNITT_TCASE rand_tests[] = {
|
|
UNITT_TCASE(test_0),
|
|
// UNITT_TCASE(test_1),
|
|
// UNITT_TCASE(test_2),
|
|
};
|
|
|
|
static UNITT suites[] = {
|
|
{ "xxx suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock },
|
|
};
|
|
|
|
UNITT_EXE(suites);
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************* Base Test ************************************/
|
|
/************************************************************************************/
|
|
|
|
static void test_create(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
|
|
if (dict)
|
|
{
|
|
printf("dict create success!!!\r\n");
|
|
}
|
|
else
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
}
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_insert(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value = 0;
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
|
|
printf("dict[ZhangSan] = %d\r\n", dict_at(dict, int, "ZhangSan"));
|
|
printf("dict[LiSi] = %d\r\n", dict_at(dict, int, "LiSi"));
|
|
printf("dict[WangWu] = %d\r\n", dict_at(dict, int, "WangWu"));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_erase(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value = 0;
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
|
|
dict_erase(dict, "LiSi");
|
|
|
|
printf("dict[ZhangSan] = %d\r\n", dict_at(dict, int, "ZhangSan"));
|
|
printf("dict[LiSi] = %d\r\n", dict_at(dict, int, "LiSi"));
|
|
printf("dict[WangWu] = %d\r\n", dict_at(dict, int, "WangWu"));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_clear(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value = 0;
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
|
|
printf("size %d\r\n", dict_size(dict));
|
|
dict_clear(dict);
|
|
printf("size %d\r\n", dict_size(dict));
|
|
|
|
printf("dict[ZhangSan] = %d\r\n", dict_at(dict, int, "ZhangSan"));
|
|
printf("dict[LiSi] = %d\r\n", dict_at(dict, int, "LiSi"));
|
|
printf("dict[WangWu] = %d\r\n", dict_at(dict, int, "WangWu"));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_find(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value = 0;
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
|
|
printf("dict_find [ZhangSan], result = %d\r\n", dict_find(dict, "ZhangSan"));
|
|
printf("dict_find [Hello], result = %d\r\n", dict_find(dict, "Hello"));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_ktype(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
dict_set_klength(dict, sizeof(int), 0);
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
dict_insert(dict, literal(int, 1024), literal(int, 1));
|
|
dict_insert(dict, literal(int, 512), literal(int, 2));
|
|
dict_insert(dict, literal(int, 128), literal(int, 3));
|
|
|
|
printf("dict[1024] = %d\r\n", dict_at(dict, int, literal(int, 1024)));
|
|
printf("dict[512] = %d\r\n", dict_at(dict, int, literal(int, 512)));
|
|
printf("dict[128] = %d\r\n", dict_at(dict, int, literal(int, 128)));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
static void test_it(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value = 0;
|
|
|
|
if (!dict)
|
|
{
|
|
printf("[ERROR] dict create fail!!!\r\n");
|
|
return;
|
|
}
|
|
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
|
|
char *key;
|
|
void *vaddr = NULL;
|
|
void *error;
|
|
if (!dict) return;
|
|
dict_it_init(dict);
|
|
error = dict_error(dict);
|
|
while (1)
|
|
{
|
|
vaddr = dict_it_get(dict, &key);
|
|
if (vaddr == error) break;
|
|
printf("key: %s,\tvalue: %d\r\n", key, *(int *)vaddr);
|
|
}
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
#if 1
|
|
static void dict_print(dict_t dict)
|
|
{
|
|
char *key;
|
|
void *value;
|
|
void *error;
|
|
if (!dict) return;
|
|
dict_it_init(dict);
|
|
error = dict_error(dict);
|
|
while (1)
|
|
{
|
|
value = dict_it_get(dict, &key);
|
|
if (value == error) break;
|
|
printf("key: %s,\tvalue: %d\r\n", key, *(int *)value);
|
|
}
|
|
}
|
|
|
|
#define TEST_COUNT 1000
|
|
static void test_performance(void)
|
|
{
|
|
#if 0
|
|
char name[10];
|
|
int len;
|
|
int i, j;
|
|
printf("char *name[%d] = {", TEST_COUNT);
|
|
for (i = 0; i < TEST_COUNT; i++)
|
|
{
|
|
len = rand() % 9 + 1;
|
|
for (j = 0; j < len; j++)
|
|
{
|
|
name[j] = rand() % ('\\' - '0') + '0';
|
|
}
|
|
name[j] = 0;
|
|
|
|
printf("\"%s\", ", name);
|
|
}
|
|
printf("};\r\n");
|
|
#else
|
|
// char *name[100] = {":A", "1?FLI1N7", "37JD:H", "[8", "QJ6F[3[", "B:>MOM", "S:MEUG0E", "D76Y6S", "XA6V@MUU4", "L9:=U10", "Z", "F", "RHWZ7<4", "TDS[>7L8D", "O", "VZ", "OC>N", "KM", "BM8@<E", "NQA", "8O4=?I", "35SEC[@", "5:A:3;", "PKL", "[?Z@T7HYX", "ZUV", "M?[L88Q", "IDF<@N", "0W?S=O", "XO1T3CNY", "?QYCYJL?7", "=DX[SA>", "8LR<0E", "U", "8", "B7R7", "9H", "=?RVMN:", "Y3WH<[>0[", "R<<B", "NI1=JNUPD", "Z>=L0V24", "JT8@T7K", "D?", "71F9R4?", "US<;I1XJ", "Z640Z<@R", "C=TSR[<", "LGA0J", ";VY=", "=?OO", "T", "CH", "MXCZPN88B", "TY><H0", "VAU:78ZV5", "2H:", "M7DL?6<G1", "@ZGLF[L", "AY3HI", "VNOXN", "B@IVD@EP", "FZPDETC", "E<", "BS>0", "860IUB[", "C=5TR", "8", ";XMQP", "NMT0", "K>0XZ6AG[", "FLOTQ[23K", ">GDGO0", "ATM", "W[", "TZGMY[X", "K3PU", "R@", "16LEN@Y", "9", "1JMD", "YBZJ", "YF", "1J0", "4:N:<", ">9Z", "7>", "@SAE;TV", ";DZ8CNM", "6", "1@5", "4", "2R@8Y60Q", "UOMNI;Y29", "YW;B1N", "U", "K", "NMPF=5", "=>", "717=KBN5", };
|
|
char *name[1000] = {":A", "1?FLI1N7", "37JD:H", "[8", "QJ6F[3[", "B:>MOM", "S:MEUG0E", "D76Y6S", "XA6V@MUU4", "L9:=U10", "Z", "F", "RHWZ7<4", "TDS[>7L8D", "O", "VZ", "OC>N", "KM", "BM8@<E", "NQA", "8O4=?I", "35SEC[@", "5:A:3;", "PKL", "[?Z@T7HYX", "ZUV", "M?[L88Q", "IDF<@N", "0W?S=O", "XO1T3CNY", "?QYCYJL?7", "=DX[SA>", "8LR<0E", "U", "8", "B7R7", "9H", "=?RVMN:", "Y3WH<[>0[", "R<<B", "NI1=JNUPD", "Z>=L0V24", "JT8@T7K", "D?", "71F9R4?", "US<;I1XJ", "Z640Z<@R", "C=TSR[<", "LGA0J", ";VY=", "=?OO", "T", "CH", "MXCZPN88B", "TY><H0", "VAU:78ZV5", "2H:", "M7DL?6<G1", "@ZGLF[L", "AY3HI", "VNOXN", "B@IVD@EP", "FZPDETC", "E<", "BS>0", "860IUB[", "C=5TR", "8", ";XMQP", "NMT0", "K>0XZ6AG[", "FLOTQ[23K", ">GDGO0", "ATM", "W[", "TZGMY[X", "K3PU", "R@", "16LEN@Y", "9", "1JMD", "YBZJ", "YF", "1J0", "4:N:<", ">9Z", "7>", "@SAE;TV", ";DZ8CNM", "6", "1@5", "4", "2R@8Y60Q", "UOMNI;Y29", "YW;B1N", "U", "K", "NMPF=5", "=>", "717=KBN5", ";2BZX", "5;QAV7G[", "1", "X62:9M<TB", ";4DR", "Z9R>4", "I=PX", ";", ";Q47WKV4P", "A", "YLOUVG;", "R18", "2Y>Z", "1>", "RV=NE7:", "9KA", "O", "CJ4", "5", "7QC9OQL5S", ":1<", "7RJ", "0", "EUAMAT", "EZTS5", ";?=D[VOAH", "5", "XWJR", "B", "L;A244", "2X;LZZ", ";BB", "6;", "?", "NOPPF3", ":PV3:Z", "MDGX", "FV", "9QAS", "4Y:E3Y9S", "PBIX<4J", "O<", ";L79[6B", "0M34JQ1M", "NEFC?", "?K8ZQ?N?", "RF;QM6YMS", "9B9;G@", "0V@?", "8", "1J7A", "GCFE7<6=M", "H6EB?8Z", "5", "EZRWJL@8", "9XSMB<<", "WIT", "IZG0QOZ", "=@B;", "QU;JEGSU", "X;28VA960", "HGS=OQN0", "I;8>HC@E", "8>PHI:QW", "Z149I", "0?R91RSJ", "CAEVQZ<", "<DZ>6", "9R5O>SPBS", "8E", "CP7X7H", "1RTQ7595", "SP4J>;@50", "@GCU4VIP:", "P49", "AZNZK;UC", "A", ">M", "W54;L[59U", "YGW", "4HLE[", "W21PY", "5V;R86?", "V0", "[M", "IJGXO", "E?H", "5C", "KKX4", "RT[ZB?N<S", "ODY", "FE9MH61I2", "D194YR", "7J<6D3T", "V:XR7MPLW", "MEW:HE", "IORZE35", "TO[WH8", ":5DA:9F", "373ZUKWGL", "R2G=", "2I", "FY?N", "I", "KZF<X3SG6", "@9M@UO6W;", "GQY>;V", "B1:M4", "KUI7L4=VE", "[=<NWL", "R77OYB", "JT2TZ", "XI", "EP42FB", "EA<", "47UY", "D4IAG6", "SM;Q<8", "P5[<7Y", "J", "HV4LEY2", "B6DS52;", "7F6C6AK<A", "W>", "F9KT=PR:R", "4X", "XF37C;5", "NPC>0T", "?JQ=STJ", "H", ";>E?O2", "95V4@D538", "UL<G[WPQ6", "?7I7B", "LQ2NE", ";", ";4;UKCUD3", "CGE7", "K7G", "PNL4>BJD", ">76I;BB", "=P", "AV9@?", "4B0KMP==<", "7W[", "9J", ":VG58T", "[", "781", "E5@E", "EMY;B0B=", "AZ2F8@1", "0=", "[C", "L", "7", "202NE7L", "IL", "VH0<2Z", "VCNVPQV7", "Z46GJ6I<3", "XTR", "W41?A3=", "YPD;X9I4", "GL>2", "D3Z", "P?SZT62", "EW", "RM=F60C?", "[G53", "LQ9779?", "0", ">KTK4O[?", "<=[=8R?", "RXN", "HW=83FG", "Z=T15C", "<CY57:HXC", ";2I894", "4AT7?@9R", "E;:XUFSRL", "18?X[KZH", "7MCPF", "W>4HH91S", "BM", "9", "1LXN", "<M3ON>>S", "2QYZ3EZ3N", "?I>D[[?0L", "N40", "7OFY2=J42", "FJ", "Y58ADQ7X", "6<9:D", ">D7Y8", ">NBYR", "EQ[ZN46", "1@N", "HTM93I1U", "8", "N>5@8", "JI[?HBE", "H06@6", "A[M", "F:3SP<2", "2LR:", "A<J8T0NA", "N[AU", ":<", "<:>T1", "H", "EJ8P<>50", "=UX[NY6", "RCMD", "=", "A30", "6HB4JJT?Y", "?=", "L:", "?K<EUO6", "VCEOFZI5Z", "91J1T[", "K=", "<[N", "JZ0C568C1", "6[3P4", "8Q3RRWRLF", "Q:FWQ4VQ[", "W7?", "<E@@MDV", ":Y4D<", "5RU>E?9N", "GDV", "SER8", ";HI", "DCNN", "RK4", "P?YF", "P7ZKOBE", "NBX", "LKV9D>5", "E", "A4", "F<=WR", "4Y[", "4B", ":H", "JBO", "<A6JZ=", "?OKUMWJ0", "K4GK<", "EY>1D@", "827199[", "=>5@LR<", ";", ">?XY3", "B0RCE6>59", "JVNITC?Z", "[8HNCYD", ">A>R;S", "NP6D=?YW", "3DF[;X", "O4?U0P=;F", "1PY<", "30CG=", "XLXCHV", "TRMGVD@V", "MI7S3X8", "L;TG:IR", ":6I:0D2", "514", "U", ";Z", "VQGRY?", "LKB", "8LDVR25:Z", "03MI5Z0T", "DO", "0YH?T8Z", "GJ", "[E", "E2", "C", "Q[R>49>", "6R4PR1<", ">Y[1DJ", "WGV", "17<6X;A:", "JHQ8RUXI>", "JLJJ5FL", "A7<:LCG", "SR7", "J", "1SAT4", "UC[W31E", "GIK@8W", "T?", "3", "T:L", "X5N=", "S3", ":FJQ", "GBF51", "QAZJ8", "MRT?", "7;0V", "U", "HHS", "JHF5C1", "DTDUR", "1:7TFZNNN", "HO0", "O0X:JXQ7", ":><2:I<P", "Z?WDQ1", "CL6JL", ">LKHNHQU", "C", "KYU9MIPK@", "4", "4:18ALT", "ZX", "Z2P8X", "KG7IATN", "H>;KB", "74", "@EFL2X", "RW", "F3C", "6CL", "<DV608A", "2N;6", "3LGOND8", "S<VV7?DJ", "LVDZ1", "6VD8I", ">", ":B5B", "IJXT", "RNF", "K4JOC", "MXC", "RXC?39A>4", "P4H>EA", "O", "K=6", "WUJB", "FU9=Q44=", "FKV", "?B", "5WB:KBU", "01TVKNT", "GFWQJC2", "AM:VDM@1", ":", "KL50M", "T", ":F;TE", "7:", "2", "P", "UCR=H6S", "A381L", "6;X5", "VA9?JT", "ZVR7>", "J5U6OL", "4O", "J@ZP3V>", "P7MHQYJP", "TWJXE7R3", "BQ[", "H1", "FQEUGY", "N2ID", "7L:D[T@D", "J[>", "P=K", "R1O[ZHG?I", "U75", "RQF:P", "3LRMK", "NTUQHK:O", "L;JC=S<X", "HN6GAW>D", "4IK", "PCZEC2", "75TVOP7", "0G?1N", "H3UV[", "BHWG<RF:", "HBUMN", "TVS", "W>J@0H", "GA:Z", "4GI", ";?6E16", ">", "FFK@=", "OKW34CC3<", "2B:", "[>", "RXRT2", "6U3LXX", "9KE57", "0", "LQ8", "7VO6L0", "H:8JS?C?C", ";", "D>R1E?2H", "S8JZ2QHNQ", ":C5<;DO2?", "=LB3BDI9Z", "59QO7;D", "AN", "K5PWTL2V", "DKH", "O[", "PL8=", "AFD0Q", "76G;94CH", "H2;", "Z?H<", "[", "NL7[A1", ">1NOM", ":XYR?EO", "[C?Y:@", "8S8VCTU", "URK>XR[", "D?", ":7", "BFEUV", "GNGOE8IA", "VNU4=7D3", "4GZM", "5KKLHXZBC", "AJII7Z", "ELVIAF1X", "IWGNM", "=PQ=MO", "4SIO@", ">", "LTCFU=DW9", "X5", "K:", "@Z[NK", "U8YBW", "1", "H", "ED", "?Q4NZ5J", "NMQ@28?", "SEI[V0>LE", "8JYL9<UQ", "<WES161", "8", "9X07ZD", "B:MW:>ELB", "@<X", "H;<SP", "T6G", "T", "F[UB0;L6J", "D3[>", "?J2JJQ>", "E9N4P8", "36WY", "W84E;", "YRV", "D", ">F", "A;3;9<A=", "1MGKHXKW", "8AT3RJZ", "G4=1", "NQCAB7:", "3PT3S@CW", "03H", "6?WH=BLJ", "EP4", "5F0TM30E", "S=FN1F", "ISX@6XN0", "<?21DB", "BBV4ZV", "0N", "FTT", "JUPZ:V", "@>WLMY5I@", "0:248A", "MGX", "?PLAJ", "?<NN", "0IP6GVO?F", "10;NA", "?X9ZPBK5D", "YPJKTJ8H8", "VXZ@3D", "S6:LYK=W", "OZD7VA?DD", "F", "8O<2", "OW67PY", "B1", "1?I@F0=N", "6E>35T", "=GXS", "36Q", "V6[Q85R", "OK", "O@7IZ", "?1", "79", "OJ>QMYF@;", "S0=YST4", "=;:Y<82", ":<RWSYE", "O7FMG:R>", "3O1W", "WM2I2>R", "YD@8?K5", "L", "DKZCUP93", "YI7PX<", "F>IP", "[8:7G=PT", "1P1[K>7UU", ":B", "BSWM=:OE4", "MS=", "HE", "ZFM", "YQ9I", "3H<Y", "6PG<E9CZ", "I3H>P", "S", "[", "RC7[4P", "7QQ5@@=", "LSH3", ">L=>ZEW9", "W", "@RK@", "?U2H3KYC", "P37", "JAK:6YLKU", "98=", "ZXUT", "O>P:", "5M>UPE6R", "90D", "4GD", "P4N:223", "::MZD2GI", "@Q>GGL", "[I?34;E=", "K[U628", "Q=:M", "Q;850F", "HJ=G743P", "HE7K", "1QF91O", ";A=04YJ4", "N4FC", "5H7=", "7", "GR:", "09Q1XO", "QE=UB", "ZR2F<EJUE", "7", "XAAOLY7U", "89>E[", ";", "NJ:DLQ8J", "E354Y1", "R8JO?C>HL", "E", "@8XF", "J", "W?JY7HE<L", "QJ", "B8SQK", "QPOOS3W7J", "R0FI3W", "K@D", ":N>V4FN", "J<3R[R", "2594PC5:", "L59", "ZMB8?P3CO", "Q=1TG", "2H", "793WLL", "5<7>[5", "AQS6TN=1", "2F7IZ95Y", "?08CL:", "XAVWZR", "OI", "0OK13MH:", "ZX", "W9", "WUF[3G", "XU:", "KC2LQ2@", "G", "FG5MF1", "UN09HZ8K", "H0?:>Z", "@KCVC<B>:", "WWCA<=3", "ZK", "6OLN", "CAEB2VEY8", "9J6XH1", "CBH", "F<6IC", "<4WCG<AA?", ">PWNBFT>", ">IA", "5JN", "8<", "Y0AUX", "5=RX055WS", "U4U?BB9J", "S=V[I7AI", ":EZS", "P8:==JI<", "M5;G[D5C", "B=", "CE[129ZD", "ML5WZVY", "6ULO47N", "P677WQJ", "Q3VBF>", "7", "DFA>DXX", "HKU", ">=WX", "FSM", "LB4ZUJ", "898M8IC", "Y@AYCN4Q", "C5?ZA0G", "W3CP68", "?TEGUYKRQ", "O86;BIO", "@5TA4=<79", "=U", "5", ">4GO", ">XLEH;9Z<", "BME:FI", ":8QNF", "Z3P", "7<WS2;D[T", "8:C4L4IW", "JW<S4B", "6", "TWICKY", "M87L", ">", "OQAS>", "6", "E1M<I3", "PXQ3", "96?X;[3WD", "LKJ2BXYI", "V", "ZKLE4", "V", "?<GE3C", "2F3Z?PI", ":0", "KIKEK1", "OFMGTG>H2", "KYGN", "KL:S:", "1N", "LOL5R5N", "L?", "X", "TE@K", "=K:8NW", "EI1FOGJB", "7", "Q", "6A8LQFX", ">G?3J1;<", "5", "Y7OLN=2", "EOF>U?[", "5YA?", "A6?[83", "H8EZS", "J", "Z5OW", "9NMIM", "N", "DE>=", "NQPQE<A", ":M3=JFBQ", "N", "3S08B6", "?KIL7OUWX", "8>", "V", "<7", "R1;", "O", "7GNTA", "3PW", "UGTN", "P1JF:YYF", "CQJNA=@", "TF@:RW", "50", "L<B3", "C", "C52@3K", "T9Y9ZQ:", ";2Y1Z?7B3", "6EVJ@", "1EFV0I5", ":GF9<8DH;", "1M8L3OD", "8R;", ":QY", "K", ":8SEOQ6DZ", "D9", "E>36AS", "FC<QDGZU", "1SBN2?ATE", ":GQCB", "QF=JQ?4", "K=HJPB:Q", "MWP0=0Z2:", "T5X", ">V<@3", "XO", "M<QANCK", "4FG", ";[G>MDJ", "@", "H", "=XQTTEZ", "97W?KZ67E", "885OF;LH1", "I27", "Z@", "S", "IQF84=S3", "C0J", "87", "7BC7X?", "ZF3XWN7", ";@7WED", "0@J", "ZML", "X;0", "CX7L>M7", "0UVMH;<", "88K", "IML[>P1;", "22WB9", "Q", "6DSDRX", "E8XMU[UB4", "UWNWJ6A4", ";>0D56@@", "7=3LEC>", "WKL[I", ">;U", "A:1BYSV", "XD", "<3", "IJ2GETQ@", "BT0@6O934", "HZT?T:;QE", "<V1VX", "SPQ", "LKD4[2", "8", "XG5?", "DK27@[K", "VLZR", "R[", "BKYVO", "XGIZX43;X", ">COOB>?", "BRGZHZ", "ZIM", "PILP", "J47N", "G", "5BATU8LI2", "H1BFQTGB4", "CP", "FSHMY", "8KXKD", "X4=Y77Z", "IXU", "DOY8J5", "4X4QU", "BX;E", "DUE", ":4@8PY5IR", "PO", "?=", "C9UMG8", "CC0<", "=RIGVZP3?", "4JRUQC8", "L", "PY<;5S6", ";", "@H9", "HG@<JO", "O=S0", "N8", ">S", ";", "H@", "7TGJ9G", "73", "GSU", "T", "030GQL", "GWBR", "BJOIC", "74", "V;=5:4", "@AVTD>", "NZ", "M=RD", "8FXRAJA", "SP84=V", "O;213Z", "W4Q", "R2IN;9", "K[", "9", "311P", ">J:1U<FY;", "<?F350", "S<=DWQF", "2123", "KA@V", "9J@J=", "VMKA", "KEF?;", ";D", "<FY>1OYV3", "PPVH?KM9<", "K[?H", "O;?B", "ONML", "NSA", ">5", "3CPB2U3", "I6", "A7", "4BZZJ", "L;Q4Z1YZ", "F7B", "W", "DQT;RZE", "I4O0FMJK", "=T=;U;N9Q", "378@KA", ">LJ;S", "?GL", "LN", "B[POOJ", "U;L6>S>", "V8>8TA", "31:JM", "O?", "5R7TE9O", "D?X", "6;Y", "W", "LO5", "R6QU", "<H27", "T>A", "04", "DCE;", "8ME3A5:", "LD4A", "?5QA<V93P", "3T0G", "Y", "QIX;L=@", };
|
|
dict_t dict = dict(int);
|
|
unsigned long long start, end;
|
|
|
|
start = reckon_usec();
|
|
for (int i = 0; i < TEST_COUNT; i++)
|
|
{
|
|
dict_insert(dict, name[i], &i);
|
|
}
|
|
end = reckon_usec();
|
|
printf("insert %llu\r\n", (unsigned long long)(end - start));
|
|
|
|
start = reckon_usec();
|
|
for (int i = 0; i < TEST_COUNT; i++)
|
|
{
|
|
dict_at(dict, int, name[rand() % TEST_COUNT]);
|
|
}
|
|
end = reckon_usec();
|
|
printf("at %llu\r\n", (unsigned long long)(end - start));
|
|
|
|
_dict(dict);
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
static void test_base(void)
|
|
{
|
|
dict_t dict = dict(int);
|
|
int value;
|
|
|
|
value = 100; dict_insert(dict, "hello", &value);
|
|
value = 1; dict_insert(dict, "ZhangSan", &value);
|
|
value = 2; dict_insert(dict, "LiSi", &value);
|
|
value = 3; dict_insert(dict, "WangWu", &value);
|
|
value = 4; dict_insert(dict, "SunLiu", &value);
|
|
value = 5; dict_insert(dict, "QianQi", &value);
|
|
value = 8; dict_insert(dict, "WangBa", &value);
|
|
value = 9; dict_insert(dict, "LiuJiu", &value);
|
|
// dict_show(dict);
|
|
// printf("-------------------------------------------------------------\r\n");
|
|
// printf("size = %d, value size = %d\r\n", dict_size(dict), dict_dsize(dict));
|
|
// dict_erase(dict, "hello");
|
|
// dict_erase(dict, "ZhangSan");
|
|
// dict_erase(dict, "LiSi");
|
|
// dict_erase(dict, "WangWu");
|
|
// dict_clear(dict);
|
|
// dict_show(dict);
|
|
// dict_print(dict);
|
|
|
|
printf("dict[ZhangSan] = %d\r\n", dict_at(dict, int, "ZhangSan"));
|
|
printf("dict[hello] = %d\r\n", dict_at(dict, int, "hello"));
|
|
printf("dict[SunLiu] = %d\r\n", dict_at(dict, int, "SunLiu"));
|
|
printf("dict[LiuJiu] = %d\r\n", dict_at(dict, int, "LiuJiu"));
|
|
|
|
_dict(dict);
|
|
|
|
dict = dict(int);
|
|
dict_set_klength(dict, sizeof(int), NULL);
|
|
|
|
dict_insert(dict, literal(int, 0), literal(int, 100));
|
|
dict_insert(dict, literal(int, 6), literal(int, 1024));
|
|
dict_insert(dict, literal(int, 5), literal(int, -1));
|
|
dict_insert(dict, literal(int, 9), literal(int, 314));
|
|
printf("%d\r\n", *(int *)dict_insert(dict, literal(int, 100), literal(int, 314)));
|
|
|
|
|
|
dict_at(dict, int, literal(int, 1000)) = 11111;
|
|
printf("dict[5] = %d\r\n", dict_at(dict, int, literal(int, 5)));
|
|
printf("dict[0] = %d\r\n", dict_at(dict, int, literal(int, 0)));
|
|
printf("dict[6] = %d\r\n", dict_at(dict, int, literal(int, 6)));
|
|
printf("dict[9] = %d\r\n", dict_at(dict, int, literal(int, 9)));
|
|
|
|
_dict(dict);
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************* Command ************************************/
|
|
/************************************************************************************/
|
|
|
|
static void usage(void)
|
|
{
|
|
printf(
|
|
"Usage: dict [opt] [arg] ...\n"
|
|
"\n"
|
|
"options:\n"
|
|
" -e <execute> Specifies the function to execute, the default is the <base> test\n"
|
|
" <base> Test base function\n"
|
|
" <ut> Unit test\n"
|
|
" <perf> Performance test\n"
|
|
" <create> Test create and delete functions\n"
|
|
" <insert> Test insert function\n"
|
|
" <erase> Test erase function\n"
|
|
" <clear> Test clear function\n"
|
|
" <find> Test find function\n"
|
|
" <ktype> Test different types of key\n"
|
|
" <it> Test traversed through iterator\n"
|
|
" -h Print help\n"
|
|
" -v Print version\n"
|
|
" -u [<period>] Unit test period, unit ms, the default is 1000ms\n"
|
|
"\n"
|
|
);
|
|
}
|
|
|
|
static int test(int argc, char *argv[])
|
|
{
|
|
char *execute = NULL;
|
|
int ut_period = 1000;
|
|
|
|
/* reset getopt */
|
|
command_opt_init();
|
|
|
|
while (1)
|
|
{
|
|
int opt = command_getopt(argc, argv, "e:hvu::");
|
|
if (opt == -1) break;
|
|
|
|
switch (opt)
|
|
{
|
|
case 'u' :
|
|
if (command_optarg) ut_period = atoi(command_optarg);
|
|
break;
|
|
case 'e' :
|
|
execute = command_optarg;
|
|
break;
|
|
case 'v' :
|
|
printf("dict version %d.%d.%d\r\n", DICT_V_MAJOR, DICT_V_MINOR, DICT_V_PATCH);
|
|
return 0;
|
|
case '?':
|
|
printf("Unknown option `%c`\r\n", command_optopt);
|
|
return -1;
|
|
case 'h' :
|
|
default:
|
|
usage();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
if (execute)
|
|
{
|
|
if (!strcmp(execute, "base"))
|
|
{
|
|
test_base();
|
|
}
|
|
else if (!strcmp(execute, "ut"))
|
|
{
|
|
#if defined(TEST_TARGET_dict)
|
|
while (1)
|
|
{
|
|
unitt_task();
|
|
usleep(1000 * ut_period);
|
|
}
|
|
#else
|
|
printf("create task %d\r\n", task_create(ut_period, unitt_task));
|
|
#endif
|
|
}
|
|
else if (!strcmp(execute, "perf"))
|
|
{
|
|
test_performance();
|
|
}
|
|
else if (!strcmp(execute, "create"))
|
|
{
|
|
test_create();
|
|
}
|
|
else if (!strcmp(execute, "insert"))
|
|
{
|
|
test_insert();
|
|
}
|
|
else if (!strcmp(execute, "erase"))
|
|
{
|
|
test_erase();
|
|
}
|
|
else if (!strcmp(execute, "clear"))
|
|
{
|
|
test_clear();
|
|
}
|
|
else if (!strcmp(execute, "find"))
|
|
{
|
|
test_find();
|
|
}
|
|
else if (!strcmp(execute, "ktype"))
|
|
{
|
|
test_ktype();
|
|
}
|
|
else if (!strcmp(execute, "it"))
|
|
{
|
|
test_it();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
test_base();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/************************************************************************************/
|
|
/************************************ Test entry ************************************/
|
|
/************************************************************************************/
|
|
|
|
#if defined(TEST_TARGET_dict)
|
|
int main(int argc, char *argv[])
|
|
{
|
|
return test(argc, argv);
|
|
}
|
|
#else
|
|
void test_dict(void)
|
|
{
|
|
command_export("dict", test);
|
|
}
|
|
init_export_app(test_dict);
|
|
#endif
|