base_data(talent_type const (&t_b_)[t_size], spell_type const (&s_b_)[s_size], effect_type const (&e_b_)[e_size]) : t_b(t_b_), t_e(t_b_ + t_size), s_b(s_b_), s_e(s_b_ + s_size), e_b(e_b_), e_e(e_b_ + e_size) { t_index = build_index(t_b, t_e, t_maxid); s_index = build_index(s_b, s_e, s_maxid); e_index = build_index(e_b, e_e, e_maxid); }
void Query::init_people() { int i; QSqlQuery query; QString sql; for (i = 0; i < PARAMETER_SIZE; i++) { this->lists[i] = NULL; } this->people = new People[11000]; this->npeople = 0; i = 0; sql = "select number,name,birthday,jointime,people,jiguan,\ bingyuan,wenhua,bingzhong,junxian,region from info"; query.exec(sql); while (query.next()) { QString number = query.value(0).toString().toUpper(); QString name = query.value(1).toString(); QString birthday = query.value(2).toString(); QString jointime = query.value(3).toString(); QString nation = query.value(4).toString(); int nativeplace = get_value_by_key(nativeplace_map, query.value(5).toString()); QString soldierhome = query.value(6).toString(); int education = get_value_by_key(education_map, query.value(7).toString()); int armtype = get_value_by_key(armtype_map, query.value(8).toString()); int military = get_value_by_key(militaryrank_map, query.value(9).toString()); int district = get_value_by_key(district_map, query.value(10).toString()); people[i].number = number; people[i].name = name; people[i].birthday = birthday; people[i].birthday = birthday; people[i].jointime = jointime; people[i].nation = nation; people[i].nativeplace = nativeplace; people[i].soldierhome = soldierhome; people[i].education = education; people[i].armtype = armtype; people[i].military = military; people[i].district = district; //void Query::build_index(People *p, int key, enum parameter_t pm) build_index(&people[i], nativeplace, NATIVEPLACE); build_index(&people[i], education, EDUCATION); build_index(&people[i], military, MILITARYRANK); build_index(&people[i], armtype, ARMTYPE); build_index(&people[i], district, DISTRICT); people_map.insert(number, i); i = i + 1; } this->npeople = i; }
girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document, void* data, zathura_error_t* error) { mupdf_document_t* mupdf_document = data; if (document == NULL || mupdf_document == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } /* get outline */ fz_outline* outline = fz_load_outline(mupdf_document->ctx, mupdf_document->document); if (outline == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_UNKNOWN; } return NULL; } /* generate index */ girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); build_index(mupdf_document->ctx, mupdf_document->document, outline, root); /* free outline */ fz_drop_outline(mupdf_document->ctx, outline); return root; }
bool net::connection_list::serialize(bool ordered, string::buffer& buf) { const node* nodes = _M_nodes.nodes; if (!ordered) { int i = _M_head; while (i != -1) { if (!nodes[i].conn.serialize(buf)) { return false; } i = nodes[i].next; } } else { if (!build_index()) { return false; } const unsigned* indices = _M_index.indices; size_t used = _M_index.used; for (size_t i = 0; i < used; i++) { if (!nodes[indices[i]].conn.serialize(buf)) { return false; } } } return true; }
filter& filter::operator=(const filter& rhs) { values_ = rhs.values_; build_index(); return *this; }
girara_tree_node_t* djvu_document_index_generate(zathura_document_t* document, djvu_document_t* djvu_document, zathura_error_t* error) { if (document == NULL || djvu_document == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } miniexp_t outline = miniexp_dummy; while ((outline = ddjvu_document_get_outline(djvu_document->document)) == miniexp_dummy) { handle_messages(djvu_document, true); } if (outline == miniexp_dummy) { return NULL; } if (miniexp_consp(outline) == 0 || miniexp_car(outline) != miniexp_symbol("bookmarks")) { ddjvu_miniexp_release(djvu_document->document, outline); return NULL; } girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); build_index(djvu_document, miniexp_cdr(outline), root); ddjvu_miniexp_release(djvu_document->document, outline); return root; }
// --------- begin of function SERes::init1 ----------// void SERes::init1() { deinit(); seed = m.get_time(); load_info(); sort_info(); build_index(); init_flag = 1; }
filter& filter::operator+=(const filter& rhs) { values_.push_back(','); values_.insert(values_.end(), rhs.values_.begin(), rhs.values_.end()); build_index(); return *this; }
void init_dict_search() { int fd = open(FILENAME, O_RDONLY); if(fd <= 0) { perror(FILENAME); exit(1); } off_t length = get_file_size(fd); dict_data = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); close(fd); word_count = read_short(dict_data, 0); index_data = build_index(length); }
int main(int argc, char *argv[]) { char *infile, *outfile; uchar *text; char *params = NULL; ulong text_len; void *index; int error, i; double start, end; if (argc < 3) print_usage(argv[0]); if (argc > 3) { int nchars, len; nchars = argc-3; for(i=2;i<argc;i++) nchars += strlen(argv[i]); params = (char *) malloc((nchars+1)*sizeof(char)); params[nchars] = '\0'; nchars = 0; for(i=3;i<argc;i++) { len = strlen(argv[i]); strncpy(params+nchars,argv[i],len); params[nchars+len] = ' '; nchars += len+1; } params[nchars-1] = '\0'; } infile = argv[1]; outfile = argv[2]; start = getTime(); error = read_file(infile, &text, &text_len); IFERROR(error); error = build_index(text, text_len, params, &index); IFERROR(error); error = save_index(index, outfile); IFERROR(error); end = getTime(); fprintf(stderr, "Building time: %.3f secs\n", end-start ); ulong index_len; index_size(index, &index_len); fprintf(stdout,"Input: %lu bytes --> Output %lu bytes.\n", text_len, index_len); fprintf(stdout,"Overall compression --> %.2f%% (%.2f bits per char).\n\n", (100.0*index_len)/text_len, (index_len*8.0)/text_len); error = free_index(index); IFERROR(error); exit(0); }
// @build_index:test_build_index_3 => [La variable count d'un mot présent cinq fois ne vaut pas 5.] void test_build_index_3(void) { char s[50]="lorem lorem lorem lorem lorem"; char *str=s; Entry *first = build_index(str); CU_ASSERT_EQUAL(first->count,5); free(first); }
int main(void) { t_node *tree; int val; tree = init_node(); val = build_index(&tree); if (val) search_index(tree); free_tree(&tree); return (0); }
// Builds index and loads probe values. For each value, the index is probed // and the range identifier is appended to an array. The array is then printed out. // takes in command line arguments in the form: build K P 9 5 9 int main(int argc, char** argv) { if(argc < 4){ printf("Usage: build K P <fanouts> \n "); return 0; } // Gathers input and builds index int levels_n = argc - 3; int k = atoi(argv[1]); int p = atoi(argv[2]); int* fanouts = malloc(levels_n * sizeof(int)); for(int f = 0; f<levels_n; f++){ fanouts[f] = atoi(argv[3+f]); } RangeIndex range_index = build_index(k, levels_n, fanouts); if(range_index.didFail == 1){ free(fanouts); return 0; } int32_t *level; for(int i=0; i<levels_n; i++){ level = range_index.index[i]; printf("\n[ "); for(int j=0; j<range_index.level_sizes[i]; j++){ if(level[j] == INT_MAX) printf("MI "); else printf("%d ", level[j]); } printf(" ] \n"); } // Generates P random values and probes index for each value rand32_t *gen = rand32_init(time(NULL)); int32_t *probes = generate(p, gen); free(gen); for(int i = 0; i<p; i++){ int range = probe(range_index, levels_n, fanouts, probes[i]); printf("probe %d: %d\n", probes[i], range); } //clean up for(int i=0; i<levels_n; i++){ free(range_index.index[i]); } free(range_index.index); free(range_index.level_sizes); free(probes); return 0; }
/*-----------------------------------------------------------------------------------------------------------------------*/ static void build_index(FIXFieldDescr* fields, uint32_t field_count, FIXFieldDescr** index) { for(uint32_t i = 0; i < field_count; ++i) { FIXFieldDescr* fld = &fields[i]; int32_t idx = fld->type->tag % FIELD_DESCR_CNT; fld->next = index[idx]; index[idx] = fld; if (fld->group_count) { build_index(fld->group, fld->group_count, fld->group_index); } } }
// @build_index:test_build_index_1 => [L'index est mal construit pour le corpus "lorem".] void test_build_index_1(void) { char s[6]="lorem"; char *str=s; Entry *first = build_index(str); CU_ASSERT_PTR_NOT_NULL(first); CU_ASSERT_STRING_EQUAL(first->word,"lorem"); CU_ASSERT_EQUAL(first->count,1); CU_ASSERT_PTR_NULL(first->next); free(first); }
static void build_index(fz_context* ctx, fz_document* document, fz_outline* outline, girara_tree_node_t* root) { if (outline == NULL || root == NULL) { return; } while (outline != NULL) { zathura_index_element_t* index_element = zathura_index_element_new(outline->title); zathura_link_target_t target = { ZATHURA_LINK_DESTINATION_UNKNOWN, NULL, 0, -1, -1, -1, -1, 0 }; zathura_link_type_t type = ZATHURA_LINK_INVALID; zathura_rectangle_t rect = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 }; if (outline->uri == NULL) { type = ZATHURA_LINK_NONE; } else if (fz_is_external_link(ctx, outline->uri) == 1) { if (strstr(outline->uri, "file://") == outline->uri) { type = ZATHURA_LINK_GOTO_REMOTE; target.value = outline->uri; } else { type = ZATHURA_LINK_URI; target.value = outline->uri; } } else { float x = 0; float y = 0; type = ZATHURA_LINK_GOTO_DEST; target.destination_type = ZATHURA_LINK_DESTINATION_XYZ; target.page_number = fz_resolve_link(ctx, document, outline->uri, &x, &y); target.left = x; target.top = y; target.zoom = 0.0; } index_element->link = zathura_link_new(type, rect, target); if (index_element->link == NULL) { outline = outline->next; continue; } girara_tree_node_t* node = girara_node_append_data(root, index_element); if (outline->down != NULL) { build_index(ctx, document, outline->down, node); } outline = outline->next; } }
// @build_index:test_build_index_2 => [Dans un corpus avec deux mots différents, la variable next du premier indexEntry ne pointe pas vers le deuxième mot.] void test_build_index_2(void) { char s[12]="lorem ipsum"; char *str=s; Entry *first = build_index(str); Entry *second = first->next; CU_ASSERT_PTR_NOT_NULL(second); if (second != NULL) CU_ASSERT_STRING_EQUAL(second->word,"ipsum"); free(first); free(second); }
/*-----------------------------------------------------------------------------------------------------------------------*/ static FIXMsgDescr* load_message(xmlNode const* msg_node, xmlNode const* root, FIXFieldType* (*ftypes)[FIELD_TYPE_CNT], FIXError** error) { FIXMsgDescr* msg = (FIXMsgDescr*)calloc(1, sizeof(FIXMsgDescr)); msg->name = _strdup(get_attr(msg_node, "name", NULL)); msg->type = _strdup(get_attr(msg_node, "type", NULL)); msg->field_count = count_msg_fields(msg_node, get_first(root, "components")); msg->fields = (FIXFieldDescr*)calloc(msg->field_count, sizeof(FIXFieldDescr)); uint32_t count = 0; if (FIX_FAILED == load_fields(msg->fields, &count, msg_node, get_first(root, "components"), ftypes, error)) { return NULL; } assert(count == msg->field_count); msg->field_index = (FIXFieldDescr**)calloc(FIELD_DESCR_CNT, sizeof(FIXFieldDescr*)); build_index(msg->fields, msg->field_count, msg->field_index); return msg; }
// @build_index:test_buid_index_5 => [build_index accède à une adresse mémoire à droite de la zone mémoire de la chaine de caractères passée en argument.] void test_build_index_5(void) { char *str; //On cherche à allouer 2 pages de la mémoire, la première avec le droit d'écriture et de lecture void *ptr = mmap(NULL, getpagesize()*2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (ptr == MAP_FAILED) { CU_FAIL("La mémoire n'a pas pu être allouée pour le test test_build_index_5."); return; } // On protège ensuite la deuxième page mémoire en enlevant les droits de lecture et écriture mprotect(ptr+getpagesize(), getpagesize(), PROT_NONE); // On écrit à la fin de la première page mémoire la chaine "lorem\0" str = (char*) ptr+getpagesize()-7; strcpy(str, "lorem"); /* Si le code de l'utilisateur accède à de la mémoire située après le caractère de fin \0, * autrement dit la mémoire protégée de la seconde page, un segfault sera envoyé. * La mécanique utilisée ici permet d'"attraper" un segfault sans que tout le programme ne plante */ //On enregistre un signal handler. Cette fonction sera exécutée par le programme lorsque //le code produira une segmentation fault (ce qui lance le signal SIGSEGV). if (signal(SIGSEGV, sig_handler2) == SIG_ERR) { CU_FAIL("Impossible d'enregistrer un signal handler."); return; } //On définit ici un jump avec le label label_test_build_index_5 qui attend le paramètre 0 (par défaut) if(setjmp(label_test_build_index_5)==0) { build_index(str); } else{ //On a reçu un autre paramètre que 0, autrement dit le code a exécuté sig_handler //On a donc intercepté une segmentation fault, donc le code de l'utilisateur est fautif. CU_ASSERT_TRUE(0); } //On enlève le signal handler précédemment assigné à SIGSEGV signal(SIGSEGV, SIG_DFL); //On libère la mémoire précédemment allouée munmap(ptr, getpagesize()*2); }
bool GzippedFileReader::OkIndex() { if (m_pIndex) return true; // Try to read index from disk wxString indexfile = iso2indexname(m_filename); if (indexfile.length() == 0) return false; // iso2indexname(...) will print errors if it can't apply the template if (wxFileName::FileExists(indexfile) && (m_pIndex = ReadIndexFromFile(indexfile))) { Console.WriteLn(Color_Green, L"OK: Gzip quick access index read from disk: '%s'", WX_STR(indexfile)); if (m_pIndex->span != GZFILE_SPAN_DEFAULT) { Console.Warning(L"Note: This index has %1.1f MB intervals, while the current default for new indexes is %1.1f MB.", (float)m_pIndex->span / 1024 / 1024, (float)GZFILE_SPAN_DEFAULT / 1024 / 1024); Console.Warning(L"It will work fine, but if you want to generate a new index with default intervals, delete this index file."); Console.Warning(L"(smaller intervals mean bigger index file and quicker but more frequent decompressions)"); } InitZstates(); return true; } // No valid index file. Generate an index Console.Warning(L"This may take a while (but only once). Scanning compressed file to generate a quick access index..."); Access *index; FILE* infile = PX_fopen_rb(m_filename); int len = build_index(infile, GZFILE_SPAN_DEFAULT, &index); printf("\n"); // build_index prints progress without \n's fclose(infile); if (len >= 0) { m_pIndex = index; WriteIndexToFile((Access*)m_pIndex, indexfile); } else { Console.Error(L"ERROR (%d): index could not be generated for file '%s'", len, WX_STR(m_filename)); free_index(index); InitZstates(); return false; } InitZstates(); return true; }
void init() { orig_strerror = dlsym(RTLD_NEXT, "strerror"); srand(time(NULL)); char *insultdir = getenv("INSULTERR_DIR"); if (insultdir == NULL) { insultdir = "/usr/share/insulterr"; } int len = strlen(insultdir); char *buf = alloca(len + 8); strncpy(buf, insultdir, len + 8); strncpy(buf + len, "/en.txt", 8); buf[len + 7] = '\0'; int fd = open_db(); if (fd < 0) { error(0, errno, "Could not open insults from %s", buf); goto default_insult; } struct stat st; if (fstat(fd, &st) < 0) { error(0, errno, "Could not stat insults file"); goto close_file; } insults = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (insults == MAP_FAILED) { error(0, errno, "Could not mmap insults file"); goto close_file; } idx = build_index(insults, st.st_size); return; close_file: close(fd); default_insult: idx = NULL; }
int main() { Qlist *ql=init_qlist(300000); //char *file="/home/dbuser/dong/dataset/uni-data/D30"; //char *file="C:/Users/Dong/uni-data/A5"; //run_assert_file(ql,file); //user_command(ql); long build_length=30e+6; double latency; struct timeval main_start,main_end; char *data_file="/home/dbuser/dong/dataset/setb-data"; gettimeofday( &main_start, NULL ); build_index(ql,data_file,build_length); gettimeofday( &main_end, NULL ); latency = 1000000 * ( main_end.tv_sec - main_start.tv_sec ) + main_end.tv_usec - main_start.tv_usec; printf("\t main building time :%lf\n",latency/1000000); show_stat_info(); return 0; }
int main(int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err = SVN_NO_ERROR; const char *repos_path; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init(argv[0], stderr) == EXIT_FAILURE) return EXIT_FAILURE; pool = svn_pool_create(NULL); if (argc <= 1) { usage_maybe_with_err(argv[0], "Not enough arguments."); goto cleanup; } /* Convert argv[1] into a UTF8, internal-format, canonicalized path. */ if ((err = svn_utf_cstring_to_utf8(&repos_path, argv[1], pool))) goto cleanup; repos_path = svn_dirent_internal_style(repos_path, pool); repos_path = svn_dirent_canonicalize(repos_path, pool); if ((err = build_index(repos_path, pool))) goto cleanup; cleanup: svn_pool_destroy(pool); if (err) { svn_handle_error2(err, stderr, FALSE, "svn-populate-node-origins-index: "); return EXIT_FAILURE; } return EXIT_SUCCESS; }
// @build_index:test_build_index_4 => [La fonction build_index ne prend pas en compte le fait que malloc puisse échouer (càd renvoyer NULL).] void test_build_index_4(void) { malloc_fail = 1; //On indique qu'on veut que malloc utilisé par build_index échoue char s[12]="lorem ipsum"; char *str=s; if(signal(SIGSEGV, sig_handler) == SIG_ERR) { CU_FAIL("Impossible d'enregistrer un signal handler."); return; } if(setjmp(label_test_build_index_4)==0) { build_index(str); } else { // On remet malloc_fail à 0 pour que CUnit puisse réutiliser malloc par la suite. malloc_fail = 0; CU_ASSERT_TRUE(0); } // On remet malloc_fail à 0 pour que CUnit puisse réutiliser malloc par la suite. malloc_fail = 0; signal(SIGSEGV, SIG_DFL); }
/**************** * RES = (BASE[0] ^ EXP[0]) * (BASE[1] ^ EXP[1]) * ... * mod M */ int mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI m) { int rc = -ENOMEM; int k; /* number of elements */ int t; /* bit size of largest exponent */ int i, j, idx; MPI *G = NULL; /* table with precomputed values of size 2^k */ MPI tmp = NULL; for(k=0; basearray[k]; k++ ) ; if (!k) { printk("mpi_mulpowm: assert(k) failed\n"); BUG(); } for(t=0, i=0; (tmp=exparray[i]); i++ ) { j = mpi_get_nbits(tmp); if( j > t ) t = j; } if (i!=k) { printk("mpi_mulpowm: assert(i==k) failed\n"); BUG(); } if (!t) { printk("mpi_mulpowm: assert(t) failed\n"); BUG(); } if (k>=10) { printk("mpi_mulpowm: assert(k<10) failed\n"); BUG(); } //daveti: hack //G = kzalloc( (1<<k) * sizeof *G, GFP_KERNEL ); G = kzalloc( (1<<k) * sizeof *G, GFP_ATOMIC ); if (!G) goto nomem; /* and calculate */ tmp = mpi_alloc( mpi_get_nlimbs(m)+1 ); if (!tmp) goto nomem; if (mpi_set_ui( res, 1 ) < 0) goto nomem; for(i = 1; i <= t; i++ ) { if (mpi_mulm(tmp, res, res, m ) < 0) goto nomem; idx = build_index( exparray, k, i, t ); if (!(idx >= 0 && idx < (1<<k))) { printk("mpi_mulpowm: assert(idx >= 0 && idx < (1<<k)) failed\n"); BUG(); } if( !G[idx] ) { if( !idx ) { G[0] = mpi_alloc_set_ui( 1 ); if (!G[0]) goto nomem; } else { for(j=0; j < k; j++ ) { if( (idx & (1<<j) ) ) { if( !G[idx] ) { if (mpi_copy( &G[idx], basearray[j] ) < 0) goto nomem; } else { if (mpi_mulm(G[idx],G[idx],basearray[j],m) < 0) goto nomem; } } } if( !G[idx] ) { G[idx] = mpi_alloc(0); if (!G[idx]) goto nomem; } } } if (mpi_mulm(res, tmp, G[idx], m ) < 0) goto nomem; } rc = 0; nomem: /* cleanup */ mpi_free(tmp); for(i=0; i < (1<<k); i++ ) mpi_free(G[i]); kfree(G); return rc; }
int main(int argc, const char *argv[]) { char word[32]; const char *filename; queue *que; node *index[26], *res, **results; /* load dictionary */ if (argc < 2) filename = "dict.txt"; else filename = argv[1]; que = load_dict(filename); /* bulid index */ build_index(que, index); /* run */ while (1) { /* input */ printf("%s", "Please input a word!\n^_^ : "); fgets(word, sizeof(word), stdin); /* remove '\n' */ if (word[strlen(word)-1] == '\n') word[strlen(word)-1] = '\0'; /* empty */ if (!strlen(word)) { putchar('\n'); continue; } /* exit */ if (strchr(word, '$')) { puts("~_~"); break; } /* search */ res = search(index, word); if (res) { search_out(res); continue; } /* similar search */ results = similar_search(index, word, results); if (*results) { printf("%s", "I can't find it. " "Show similar? (y/n): "); if (confirm()) similar_search_out(results); else putchar('\n'); } else { /* nothing */ puts("-_- : Sorry, no results!\n"); } free(results); } /* unload dictionary */ unload_dict(que); return 0; }
int main (int argc, char *argv[]) { SHPHandle inSHP, outSHP; DBFHandle inDBF, outDBF; int len; int i; char **fieldNames; char **strOrder = 0; struct DataStruct *index; int width; int decimals; SHPObject *feat; void *tuple; if (argc < 4) { printf("USAGE: shpsort <infile> <outfile> <field[;...]> [<(ASCENDING|DESCENDING)[;...]>]\n"); exit(EXIT_FAILURE); } inSHP = SHPOpen (argv[1], "rb"); if (!inSHP) { fputs("Couldn't open shapefile for reading!\n", stderr); exit(EXIT_FAILURE); } SHPGetInfo(inSHP, &nShapes, &shpType, NULL, NULL); /* If we can open the inSHP, open its DBF */ inDBF = DBFOpen (argv[1], "rb"); if (!inDBF) { fputs("Couldn't open dbf file for reading!\n", stderr); exit(EXIT_FAILURE); } /* Parse fields and validate existence */ fieldNames = split(argv[3], ";"); if (!fieldNames) { fputs("ERROR: parsing field names!\n", stderr); exit(EXIT_FAILURE); } for (nFields = 0; fieldNames[nFields] ; nFields++) { continue; } fldIdx = malloc(sizeof *fldIdx * nFields); if (!fldIdx) { fputs("malloc failed!\n", stderr); exit(EXIT_FAILURE); } for (i = 0; i < nFields; i++) { len = (int)strlen(fieldNames[i]); while(len > 0) { --len; fieldNames[i][len] = (char)toupper((unsigned char)fieldNames[i][len]); } fldIdx[i] = DBFGetFieldIndex(inDBF, fieldNames[i]); if (fldIdx[i] < 0) { /* try "SHAPE" */ if (strcmp(fieldNames[i], "SHAPE") == 0) { fldIdx[i] = -1; } else if (strcmp(fieldNames[i], "FID") == 0) { fldIdx[i] = -2; } else { fprintf(stderr, "ERROR: field '%s' not found!\n", fieldNames[i]); exit(EXIT_FAILURE); } } } /* set up field type array */ fldType = malloc(sizeof *fldType * nFields); if (!fldType) { fputs("malloc failed!\n", stderr); exit(EXIT_FAILURE); } for (i = 0; i < nFields; i++) { if (fldIdx[i] < 0) { fldType[i] = fldIdx[i]; } else { fldType[i] = DBFGetFieldInfo(inDBF, fldIdx[i], NULL, &width, &decimals); if (fldType[i] == FTInvalid) { fputs("Unrecognized field type in dBASE file!\n", stderr); exit(EXIT_FAILURE); } } } /* set up field order array */ fldOrder = malloc(sizeof *fldOrder * nFields); if (!fldOrder) { fputs("malloc failed!\n", stderr); exit(EXIT_FAILURE); } for (i = 0; i < nFields; i++) { /* default to ascending order */ fldOrder[i] = ASCENDING; } if (argc > 4) { strOrder = split(argv[4], ";"); if (!strOrder) { fputs("ERROR: parsing fields ordering!\n", stderr); exit(EXIT_FAILURE); } for (i = 0; i < nFields && strOrder[i]; i++) { if (strcmp(strOrder[i], "DESCENDING") == 0) { fldOrder[i] = DESCENDING; } } } /* build the index */ index = build_index (inSHP, inDBF); /* Create output shapefile */ outSHP = SHPCreate(argv[2], shpType); if (!outSHP) { fprintf(stderr, "%s:%d: couldn't create output shapefile!\n", __FILE__, __LINE__); exit(EXIT_FAILURE); } /* Create output dbf */ outDBF = DBFCloneEmpty(inDBF, argv[2]); if (!outDBF) { fprintf(stderr, "%s:%d: couldn't create output dBASE file!\n", __FILE__, __LINE__); exit(EXIT_FAILURE); } /* Copy projection file, if any */ copy_related(argv[1], argv[2], ".shp", ".prj"); /* Copy metadata file, if any */ copy_related(argv[1], argv[2], ".shp", ".shp.xml"); /* Write out sorted results */ for (i = 0; i < nShapes; i++) { feat = SHPReadObject(inSHP, index[i].record); if (SHPWriteObject(outSHP, -1, feat) < 0) { fprintf(stderr, "%s:%d: error writing shapefile!\n", __FILE__, __LINE__); exit(EXIT_FAILURE); } tuple = (void *) DBFReadTuple(inDBF, index[i].record); if (DBFWriteTuple(outDBF, i, tuple) < 0) { fprintf(stderr, "%s:%d: error writing dBASE file!\n", __FILE__, __LINE__); exit(EXIT_FAILURE); } } SHPClose(inSHP); SHPClose(outSHP); DBFClose(inDBF); DBFClose(outDBF); return EXIT_SUCCESS; }
void mpi_mulpowm( MPI res, MPI *basearray, MPI *exparray, MPI m) { int k; /* number of elements */ int t; /* bit size of largest exponent */ int i, j, idx; MPI *G; /* table with precomputed values of size 2^k */ MPI tmp; #ifdef USE_BARRETT MPI barrett_y, barrett_r1, barrett_r2; int barrett_k; #endif for(k=0; basearray[k]; k++ ) ; passert(k); for(t=0, i=0; (tmp=exparray[i]); i++ ) { /*log_mpidump("exp: ", tmp );*/ j = mpi_get_nbits(tmp); if( j > t ) t = j; } /*log_mpidump("mod: ", m );*/ passert(i==k); passert(t); passert( k < 10 ); #ifdef PLUTO m_alloc_ptrs_clear(G, 1<<k); #else G = m_alloc_clear( (1<<k) * sizeof *G ); #endif #ifdef USE_BARRETT barrett_y = init_barrett( m, &barrett_k, &barrett_r1, &barrett_r2 ); #endif /* and calculate */ tmp = mpi_alloc( mpi_get_nlimbs(m)+1 ); mpi_set_ui( res, 1 ); for(i = 1; i <= t; i++ ) { barrett_mulm(tmp, res, res, m, barrett_y, barrett_k, barrett_r1, barrett_r2 ); idx = build_index( exparray, k, i, t ); passert( idx >= 0 && idx < (1<<k) ); if( !G[idx] ) { if( !idx ) G[0] = mpi_alloc_set_ui( 1 ); else { for(j=0; j < k; j++ ) { if( (idx & (1<<j) ) ) { if( !G[idx] ) G[idx] = mpi_copy( basearray[j] ); else barrett_mulm( G[idx], G[idx], basearray[j], m, barrett_y, barrett_k, barrett_r1, barrett_r2 ); } } if( !G[idx] ) G[idx] = mpi_alloc(0); } } barrett_mulm(res, tmp, G[idx], m, barrett_y, barrett_k, barrett_r1, barrett_r2 ); } /* cleanup */ mpi_free(tmp); #ifdef USE_BARRETT mpi_free(barrett_y); mpi_free(barrett_r1); mpi_free(barrett_r2); #endif for(i=0; i < (1<<k); i++ ) mpi_free(G[i]); m_free(G); }
TextIndexCSA::TextIndexCSA(uchar *text, ulong length, char *build_options){ void *index; build_index(text, length, build_options, &index); csa = (CSA *) index; }
int main(int argc, char *argv[]) { char *infile, *outfile; uchar *text; ulong text_len; void *index; int error; if (argc < 3) print_usage(argv[0]); infile = argv[1]; // input file outfile = argv[2]; // output file error = read_file(infile, &text, &text_len); IFERROR(error); /* Possible options: "-a x": indicates the behaviour of FM-index with the pointer 'text'. x == 0 FM-index uses 'text' directly to build the suffix array. This means that you are responsable to allocate 'length+overshoot' bytes for the text instead of 'length' bytes. You must include ds_ssort.h. See function read_file(); x == 1 FM-index frees the allocated memory for the 'text'. overshoot and ds_ssort.h are not necessary. x == 2 FM-index makes its internal copy of 'text'. After the call, 'text' is available. overshoot and ds_ssort.h are not necessary. -B Bsize: where Bsize is the size in Kbytes of level 1 buckets. -b bsize: where bsize is the size in bytes of level 2 buckets. bsize must divide Bsize*1024; -f frequency: where frequency is a number from 0 to 1 that indicates the frequency of the marked characters. default "-b 512 -B 16 -f 0.02 -a 1" Example of some call to build_index(): - build_index(text, text_len, NULL, &index); uses the default parameters. - build_index(text, text_len, "-a 1 -f 0.1", &index); tries to mark 10% of the positions instead of 2% but I cannot reuse 'text' after this call. */ fprintf(stdout, "Building\n"); error = build_index(text, text_len, "-a 1", &index); IFERROR(error); ulong index_len; index_size(index, &index_len); fprintf(stdout,"Input: %lu bytes --> Output %lu bytes.\n", text_len, index_len); fprintf(stdout,"Overall compression --> %.2f%% (%.2f bits per char).\n\n", (100.0*index_len)/text_len, (index_len*8.0)/text_len); uchar *snippet; ulong i, readen, from = 11, to = 100, numocc, *occ; error = extract(index, from, to, &snippet, &readen); IFERROR(error); fprintf(stdout, "try extract\n\n"); for(i=0;i<readen;i++) printf("%c", snippet[i]); printf("\n"); uchar *pattern = snippet; fprintf(stdout, "try count\n\n"); error = count (index, pattern, 5, &numocc); printf("pattern: "); fwrite(pattern, sizeof(uchar), 5, stdout); printf(" # occs %lu\n\n",numocc); fprintf(stdout, "try locate\n\n"); error = locate (index, pattern, 5, &occ, &numocc); IFERROR (error); for(i=0;i<numocc;i++) printf("pos %lu\n", occ[i]); printf("\n"); free(snippet); if(numocc) free(occ); error = save_index(index, outfile); IFERROR(error); error = free_index(index); IFERROR(error); exit(0); }