Annotation of libelwix/example/test_index.c, revision 1.1.2.1
1.1.2.1 ! misho 1: #include <stdio.h>
! 2: #include <string.h>
! 3: #include <stdlib.h>
! 4: #include <elwix.h>
! 5:
! 6:
! 7: int
! 8: main(int argc, char **argv)
! 9: {
! 10: index_t *idx;
! 11: index_list_t lst;
! 12: int i;
! 13: u_short k;
! 14: array_t *arr;
! 15: char str[256];
! 16: ait_val_t *v;
! 17:
! 18: if (!(idx = index_Init(NULL)))
! 19: return 1;
! 20:
! 21: for (i = 0; i < argc; i++) {
! 22: k = crcFletcher16((u_short*) argv[i], strlen(argv[i]) / 2);
! 23: index_add(idx, k, argv[i], strlen(argv[i]), NULL);
! 24: }
! 25:
! 26: index_dump(idx);
! 27:
! 28: printf("input key=");
! 29: scanf("%hu", &k);
! 30: arr = index_getArray(idx, k);
! 31: if (!arr)
! 32: printf("error in array!!!\n");
! 33: else {
! 34: for (i = 0; i < array_Size(arr); i++) {
! 35: lst = array_Get(arr, i);
! 36: printf("Array[%d]: hash=0x%x ptr=%s len=%lu\n", i,
! 37: index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
! 38: }
! 39: array_Destroy(&arr);
! 40: }
! 41:
! 42: lst = index_getList(idx, k);
! 43: if (!lst)
! 44: printf("Key list is empty!\n");
! 45: else
! 46: while (lst) {
! 47: printf("GetList[%hu]:: hash=0x%x ptr=%s len=%lu\n", k,
! 48: index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
! 49: lst = index_Next(lst);
! 50: }
! 51:
! 52: printf("input key=");
! 53: scanf("%hu", &k);
! 54: memset(str, 0, sizeof str);
! 55: printf("input hash=");
! 56: scanf("%255s", str);
! 57: i = strtol(str, NULL, 0);
! 58: lst = index_get2(idx, k, i);
! 59: v = index_getVar(idx, k, i);
! 60: if (!lst)
! 61: printf("Item not found!!!\n");
! 62: else
! 63: printf("Get2:: hash=0x%x ptr=%s len=%lu\n",
! 64: index_Hash(lst), (const char*) index_Ptr(lst), index_Len(lst));
! 65: if (!v)
! 66: printf("Item not found!!!\n");
! 67: else {
! 68: printf("GetVar:: ptr=%s len=%u\n",
! 69: (const char*) AIT_GET_PTR(v), AIT_LEN(v));
! 70: ait_freeVar(&v);
! 71: }
! 72:
! 73: printf("delete key=");
! 74: scanf("%hu", &k);
! 75: index_delList(idx, k);
! 76: index_dump(idx);
! 77:
! 78: printf("delete key=");
! 79: scanf("%hu", &k);
! 80: memset(str, 0, sizeof str);
! 81: printf("input str=");
! 82: scanf("%255s", str);
! 83: index_del(idx, k, str, strlen(str));
! 84: index_dump(idx);
! 85:
! 86: printf("delete key=");
! 87: scanf("%hu", &k);
! 88: memset(str, 0, sizeof str);
! 89: printf("input hash=");
! 90: scanf("%255s", str);
! 91: i = strtol(str, NULL, 0);
! 92: index_del2(idx, k, i);
! 93: index_dump(idx);
! 94:
! 95: index_Destroy(&idx);
! 96: return 0;
! 97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>