File:
[ELWIX - Embedded LightWeight unIX -] /
libelwix /
example /
test_index.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs -
revision graph
Thu Jan 6 15:13:01 2022 UTC (2 years, 7 months ago) by
misho
Branches:
MAIN
CVS tags:
elwix6_1,
elwix5_9,
elwix5_8,
elwix5_7,
elwix5_6,
elwix5_5,
elwix5_4,
elwix5_3,
elwix5_2,
elwix5_12,
elwix5_11,
elwix5_10,
elwix5_1,
HEAD,
ELWIX6_0,
ELWIX5_9,
ELWIX5_8,
ELWIX5_7,
ELWIX5_6,
ELWIX5_5,
ELWIX5_4,
ELWIX5_3,
ELWIX5_2,
ELWIX5_11,
ELWIX5_10,
ELWIX5_1,
ELWIX5_0
Version 5.0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <elwix.h>
int
main(int argc, char **argv)
{
index_t *idx;
index_list_t lst;
int i;
u_short k;
array_t *arr;
char str[256];
ait_val_t *v;
if (!(idx = index_Init(NULL)))
return 1;
for (i = 0; i < argc; i++) {
k = crcFletcher16((u_short*) argv[i], strlen(argv[i]) / 2);
index_add(idx, k, argv[i], strlen(argv[i]), NULL);
}
index_dump(idx);
printf("input key=");
scanf("%hu", &k);
arr = index_getArray(idx, k);
if (!arr)
printf("error in array!!!\n");
else {
for (i = 0; i < array_Size(arr); i++) {
lst = array_Get(arr, i);
printf("Array[%d]: hash=0x%x ptr=%s len=%lu\n", i,
index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
}
array_Destroy(&arr);
}
lst = index_getList(idx, k);
if (!lst)
printf("Key list is empty!\n");
else
while (lst) {
printf("GetList[%hu]:: hash=0x%x ptr=%s len=%lu\n", k,
index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
lst = index_Next(lst);
}
printf("input key=");
scanf("%hu", &k);
memset(str, 0, sizeof str);
printf("input hash=");
scanf("%255s", str);
i = strtol(str, NULL, 0);
lst = index_get2(idx, k, i);
v = index_getVar(idx, k, i);
if (!lst)
printf("Item not found!!!\n");
else
printf("Get2:: hash=0x%x ptr=%s len=%lu\n",
index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
if (!v)
printf("Item not found!!!\n");
else {
printf("GetVar:: ptr=%s len=%u\n",
(const char*) AIT_GET_PTR(v), AIT_LEN(v));
ait_freeVar(&v);
}
printf("delete key=");
scanf("%hu", &k);
index_delList(idx, k);
index_dump(idx);
printf("delete key=");
scanf("%hu", &k);
memset(str, 0, sizeof str);
printf("input str=");
scanf("%255s", str);
index_del(idx, k, str, strlen(str));
index_dump(idx);
printf("delete key=");
scanf("%hu", &k);
memset(str, 0, sizeof str);
printf("input hash=");
scanf("%255s", str);
i = strtol(str, NULL, 0);
index_del2(idx, k, i);
index_dump(idx);
index_Destroy(&idx);
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>