int main( int argc, char **args ) { //create a new array list. friso_array_t array = new_array_list(); fstring keys[] = { "chenmanwen", "yangqinghua", "chenxin", "luojiangyan", "xiaoyanzi", "bibi", "zhangrenfang", "yangjian", "liuxiao", "pankai", "chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo", "caizaili", "panpan", "xiaolude", "yintanwen" }; int j, idx = 2, len = sizeof( keys ) / sizeof( fstring ); for ( j = 0; j < len; j++ ) { array_list_add( array, keys[j] ); } printf("length=%d, allocations=%d\n", array->length, array->allocs ); array_list_trim( array ); printf("after tirm length=%d, allocations=%d\n", array->length, array->allocs ); printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) ); printf("\nAfter set %dth item.\n", idx ); array_list_set( array, idx, "chenxin__" ); printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) ); printf("\nAfter remove %dth item.\n", idx ); array_list_remove( array, idx ); printf("length=%d, allocations=%d\n", array->length, array->allocs ); printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) ); printf("\nInsert a item at %dth\n", idx ); array_list_insert( array, idx, "*chenxin*" ); printf("idx=%d, value=%s\n", idx, ( fstring ) array_list_get( array, idx ) ); free_array_list( array ); return 0; }
int main() { { void* table[2]; ArrayList buf = new_array_list(table); check_int(2, buf.capacity); check_int((size_t)0, buf.size(&buf)); check_int(table, buf.pBuf); char str1[] = "hello"; buf.add(&buf, str1); check_int(2, buf.capacity); check_int((size_t)1, buf.size(&buf)); check_int(table, buf.pBuf); char str2[] = "world"; buf.add(&buf, str2); check_int(2, buf.capacity); check_int((size_t)2, buf.size(&buf)); check_int(table, buf.pBuf); //check_int(str1, buf.remove(&buf, str1)); check_str(str1, (char*)buf.remove(&buf, str1)); check_int(2, buf.capacity); check_int((size_t)1, buf.size(&buf)); check_str(str2, (char*)buf.get(&buf, 0)); check_int(NULL, buf.remove(&buf, str1)); check_int(2, buf.capacity); check_int((size_t)1, buf.size(&buf)); check_str(str2, (char*)buf.get(&buf, 0)); //check_int(str2, buf.remove(&buf, str2)); check_str(str2, (char*)buf.remove(&buf, str2)); check_int(2, buf.capacity); check_int((size_t)0, buf.size(&buf)); check_int(NULL, buf.remove(&buf, str2)); } { char tmpFileName[L_tmpnam + 1]; tmpnam(tmpFileName); FILE* fp = fopen(tmpFileName, "wb"); check_bool(true, write_int(fp, 1231)); check_bool(true, write_int(fp, 1)); check_bool(true, write_int(fp, 441)); check_int(0, fclose(fp)); int_sorter(tmpFileName); fp = fopen(tmpFileName, "rb"); check_int(1, read_int(fp)); check_int(441, read_int(fp)); check_int(1231, read_int(fp)); check_int(0, fclose(fp)); } { char tmpFileName[L_tmpnam + 1]; tmpnam(tmpFileName); FILE* fp = fopen(tmpFileName, "w"); check_int(0, fclose(fp)); int_sorter(tmpFileName); } { int_sorter("--------------xxxxxxxxxxxxxxxxxxxxx"); } }
/* * get the next cjk word from the current position, with complex mode. * this is the core of the mmseg chinese word segemetation algorithm. * we use four rules to filter the matched chunks and get the best one * as the final result. * * @see mmseg_core_invoke( chunks ); */ __STATIC_API__ friso_hits_t next_complex_cjk( friso_t friso, friso_task_t task ) { register uint_t x, y, z; /*bakup the task->bytes here*/ uint_t __idx__ = task->bytes; lex_entry_t fe, se, te; friso_chunk_t e; friso_array_t words, chunks; friso_array_t smatch, tmatch, fmatch = get_next_match( friso, task, task->idx ); /* * here: * if the length of the fmatch is 1, mean we don't have to * continue the following work. ( no matter what we get the same result. ) */ if ( fmatch->length == 1 ) { task->hits->word = ( ( lex_entry_t ) fmatch->items[0] )->word; task->hits->type = __FRISO_SYS_WORDS__; free_array_list( fmatch ); return task->hits; } chunks = new_array_list(); task->idx -= __idx__; for ( x = 0; x < fmatch->length; x++ ) { /*get the word and try the second layer match*/ fe = ( lex_entry_t ) array_list_get( fmatch, x ); __idx__ = task->idx + fe->length; read_next_word( task, &__idx__, task->buffer ); if ( task->bytes != 0 && utf8_cjk_string( get_utf8_unicode( task->buffer ) ) && friso_dic_match( friso->dic, __LEX_CJK_WORDS__, task->buffer ) ) { //get the next matchs smatch = get_next_match( friso, task, __idx__ ); for ( y = 0; y < smatch->length; y++ ) { /*get the word and try the third layer match*/ se = ( lex_entry_t ) array_list_get( smatch, y ); __idx__ = task->idx + fe->length + se->length; read_next_word( task, &__idx__, task->buffer ); if ( task->bytes != 0 && utf8_cjk_string( get_utf8_unicode( task->buffer ) ) && friso_dic_match( friso->dic, __LEX_CJK_WORDS__, task->buffer ) ) { //get the matchs. tmatch = get_next_match( friso, task, __idx__ ); for ( z = 0; z < tmatch->length; z++ ) { te = ( lex_entry_t ) array_list_get( tmatch, z ); words = new_array_list_with_opacity(3); array_list_add( words, fe ); array_list_add( words, se ); array_list_add( words, te ); array_list_add( chunks, new_chunk( words, fe->length + se->length + te->length ) ); } free_array_list( tmatch ); } else { words = new_array_list_with_opacity(2); array_list_add( words, fe ); array_list_add( words, se ); //add the chunk array_list_add( chunks, new_chunk( words, fe->length + se->length ) ); } } free_array_list( smatch ); } else { words = new_array_list_with_opacity(1); array_list_add( words, fe ); array_list_add( chunks, new_chunk( words, fe->length ) ); } } free_array_list( fmatch ); /* * filter the chunks with the four rules of the mmseg algorithm * and get best chunk as the final result. * @see mmseg_core_invoke( chunks ); * @date 2012-12-13 */ if ( chunks->length > 1 ) { e = mmseg_core_invoke( chunks ); } else { e = ( friso_chunk_t ) chunks->items[0]; } fe = ( lex_entry_t ) e->words->items[0]; task->hits->word = fe->word; task->hits->type = __FRISO_SYS_WORDS__; task->idx += fe->length; //reset the idx of the task. free_chunk( e->words ); free_chunk( e ); return task->hits; }