int main() { int i,ret; char key[KSIZE]; char val[VSIZE]; struct slice sk,sv; struct index *idx=index_new("test_idx",MAX_MTBL,MAX_MTBL_SIZE); for(i=0;i < LOOP;i++){ snprintf(key,KSIZE,"key:%d",i); snprintf(val,VSIZE,"val:%d",i); sk.len=KSIZE; sk.data=key; sv.len=VSIZE; sv.data=val; ret=index_add(idx,&sk,&sv); if(!ret) __DEBUG("%s","Write failed...."); } return 0; }
index_t *index_load(int32_t fd, int32_t offset, int32_t size) { int32_t id; int32_t len; index_t *l; int8_t *buffer, *ptr; meta_t *o; if (fd < 0 || offset < 0 || size < 0) return(NULL); if ((l = index_new()) == NULL) return(NULL); if ((buffer = malloc(size)) == NULL) __ERROR_LOG(B_ERROR); lseek(fd,offset,SEEK_SET); if (size != read(fd,buffer,size)) __ERROR_LOG(R_ERROR); ptr = buffer; l->magic = *(uint64_t *)ptr; ptr = ptr + sizeof(uint64_t); if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t))) __ERROR_LOG(C_ERROR); id = 0; /* inode id */ while (ptr - buffer < size) { if ((o = meta_new()) == NULL) break; o->offset = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->blocksize = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); len = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->key = sdsnnew(ptr,len); ptr = ptr + len; if (o->key == NULL) { meta_free(o); continue; } o->id = id++; index_add(l,o); } free(buffer); return(l); C_ERROR: R_ERROR: free(buffer); B_ERROR: index_free(l); return(NULL); }
/*---------------------------------------------------------------------------*/ static void line_statements(void) { line_num = tokenizer_num(); DEBUG_PRINTF("----------- Line number %d ---------\n", line_num); index_add(line_num, tokenizer_pos()); accept_tok(TOKENIZER_NUMBER); statements(); return; }
/* look up a symbol in the map */ static void index_symbol(t_index *x, t_symbol *s) { int element; if ( (element = find_item(s, x->names, x->maxentries)+1) ) outlet_float(x->x_obj.ob_outlet, (t_float)element); else if (x->auto_mode) /* not yet stored: add automatically */ index_add(x, s, 0); else outlet_float(x->x_obj.ob_outlet, 0.f); /* not yet stored but do not add */ }
/*---------------------------------------------------------------------------*/ static void line_statement(void) { DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_num()); index_add(tokenizer_num(), tokenizer_pos()); accept(TOKENIZER_NUMBER); statement(); return; }
void send_support_q(string host, mixed port, string cmd, string param) { int idx; function f; if(!ACCESS_CHECK(previous_object())) return; if (!param) param = ""; f = (: previous_object(), "support_q_callback" :); idx = index_add(f); DNS_MASTER->send_udp(host, port, sprintf("@@@%s||NAME:%s||PORTUDP:%d||CMD:%s||ANSWERID:%d@@@\n", DNS_SUPPORT_Q, Mud_name(), udp_port(), cmd + (strlen(param) ? "||PARAM:"+param : ""), idx)); }
int index_copy(const struct index *src, struct index *dest) { int n; index_blank(dest); if (index_reserve(dest, src->entries) == -1) return -1; for (n = 0; n < src->entries; n++) index_add(dest, src->record[n]); return 0; }
void _write_test(long int count) { int i; double cost; long long start, end; struct slice sk, sv; struct index *idx; char key[KSIZE]; char val[VSIZE]; idx = _get_idx(); printf("count : %ld, idx : %p\n", count, idx); start = _ustime(); for (i = 0; i < count; i++) { _random_key(key, KSIZE); snprintf(val, VSIZE, "val:%d", i); sk.len = KSIZE; sk.data = key; sv.len = VSIZE; sv.data = val; index_add(idx, &sk, &sv); if ((i % 10000) == 0) { fprintf(stderr, "random write finished %d ops%30s\r", i, ""); fflush(stderr); } } index_free(idx); end = _ustime(); cost = end - start; printf(LINE); printf("|Random-Write (done:%ld): %.6f sec/op; %.1f writes/sec(estimates); cost:%.3f(sec)\n", count, (double)(cost / count), (double)(count / cost), cost); }
int index_match(struct index *src, struct index *dest, const struct match *match) { int n; struct record *re; index_blank(dest); for (n = 0; n < src->entries; n++) { re = src->record[n]; if (record_match(re, match)) { if (index_reserve(dest, 1) == -1) return -1; index_add(dest, re); } } return 0; }
int main(int argc, char **argv) { const char *shortopts = "acdfhrsCSVv"; struct option longopts[] = { { "add", no_argument, NULL, 'a' }, { "clean", no_argument, NULL, 'c' }, { "debug", no_argument, NULL, 'd' }, { "force", no_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "remove-obsoletes", no_argument, NULL, 'r' }, { "version", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'v' }, { "privkey", required_argument, NULL, 0}, { "signedby", required_argument, NULL, 1}, { "sign", no_argument, NULL, 's'}, { "sign-pkg", no_argument, NULL, 'S'}, { "hashcheck", no_argument, NULL, 'C' }, { NULL, 0, NULL, 0 } }; struct xbps_handle xh; const char *privkey = NULL, *signedby = NULL; int rv, c, flags = 0; bool add_mode, clean_mode, rm_mode, sign_mode, sign_pkg_mode, force, hashcheck; add_mode = clean_mode = rm_mode = sign_mode = sign_pkg_mode = force = hashcheck = false; while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { case 0: privkey = optarg; break; case 1: signedby = optarg; break; case 'a': add_mode = true; break; case 'c': clean_mode = true; break; case 'd': flags |= XBPS_FLAG_DEBUG; break; case 'f': force = true; break; case 'h': usage(false); /* NOTREACHED */ case 'r': rm_mode = true; break; case 's': sign_mode = true; break; case 'C': hashcheck = true; break; case 'S': sign_pkg_mode = true; break; case 'v': flags |= XBPS_FLAG_VERBOSE; break; case 'V': printf("%s\n", XBPS_RELVER); exit(EXIT_SUCCESS); } } if ((argc == optind) || (!add_mode && !clean_mode && !rm_mode && !sign_mode && !sign_pkg_mode)) { usage(true); } else if ((add_mode && (clean_mode || rm_mode || sign_mode || sign_pkg_mode)) || (clean_mode && (add_mode || rm_mode || sign_mode || sign_pkg_mode)) || (rm_mode && (add_mode || clean_mode || sign_mode || sign_pkg_mode)) || (sign_mode && (add_mode || clean_mode || rm_mode || sign_pkg_mode)) || (sign_pkg_mode && (add_mode || clean_mode || rm_mode || sign_mode))) { fprintf(stderr, "Only one mode can be specified: add, clean, " "remove-obsoletes, sign or sign-pkg.\n"); exit(EXIT_FAILURE); } /* initialize libxbps */ memset(&xh, 0, sizeof(xh)); xh.flags = flags; if ((rv = xbps_init(&xh)) != 0) { fprintf(stderr, "failed to initialize libxbps: %s\n", strerror(rv)); exit(EXIT_FAILURE); } if (add_mode) rv = index_add(&xh, optind, argc, argv, force); else if (clean_mode) rv = index_clean(&xh, argv[optind], hashcheck); else if (rm_mode) rv = remove_obsoletes(&xh, argv[optind]); else if (sign_mode) rv = sign_repo(&xh, argv[optind], privkey, signedby); else if (sign_pkg_mode) rv = sign_pkgs(&xh, optind, argc, argv, privkey, force); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); }
int main(int argc, char **argv) { const char *shortopts = "acfhrV"; struct option longopts[] = { { "add", no_argument, NULL, 'a' }, { "clean", no_argument, NULL, 'c' }, { "force", no_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "remove-obsoletes", no_argument, NULL, 'r' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; struct xbps_handle xh; int rv, c; bool clean_mode = false, add_mode = false, rm_mode = false, force = false; while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { case 'a': add_mode = true; break; case 'c': clean_mode = true; break; case 'f': force = true; break; case 'h': usage(false); /* NOTREACHED */ case 'r': rm_mode = true; break; case 'V': printf("%s\n", XBPS_RELVER); exit(EXIT_SUCCESS); } } if ((argc == optind) || (!add_mode && !clean_mode && !rm_mode)) { usage(true); } else if ((add_mode && (clean_mode || rm_mode)) || (clean_mode && (add_mode || rm_mode)) || (rm_mode && (add_mode || clean_mode))) { fprintf(stderr, "Only one mode can be specified: add, clean " "or remove-obsoletes.\n"); exit(EXIT_FAILURE); } /* initialize libxbps */ memset(&xh, 0, sizeof(xh)); if ((rv = xbps_init(&xh)) != 0) { fprintf(stderr, "failed to initialize libxbps: %s\n", strerror(rv)); exit(EXIT_FAILURE); } if (add_mode) rv = index_add(&xh, argc - optind, argv + optind, force); else if (clean_mode) rv = index_clean(&xh, argv[optind]); else if (rm_mode) rv = remove_obsoletes(&xh, argv[optind]); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); }