static LIST_IT_CALLBK(count_sons) { TREE_OBJ(struct tex_tr, p, tnd); P_CAST(cnt, uint32_t, pa_extra); p->rank = (*cnt) ++; LIST_GO_OVER; }
static LIST_IT_CALLBK(assign_path_id_in_order) { LIST_OBJ(struct subpath, sp, ln); P_CAST(new_path_id, uint32_t, pa_extra); /* assign path_id in order */ sp->path_id = (*new_path_id) ++; LIST_GO_OVER; }
TYPED_TEST_P(TestCast, priority_cast_integer) { EXPECT_EQ( "integer", P_CAST(i, n) ); EXPECT_EQ( "integer", P_CAST(i, b) ); EXPECT_EQ( "integer", P_CAST(i, i) ); EXPECT_EQ( "real", P_CAST(i, r) ); EXPECT_EQ( "string", P_CAST(i, s) ); EXPECT_EQ( "array", P_CAST(i, a) ); }
TYPED_TEST_P(TestCast, priority_cast_boolean) { EXPECT_EQ( "boolean", P_CAST(b, n) ); EXPECT_EQ( "boolean", P_CAST(b, b) ); EXPECT_EQ( "integer", P_CAST(b, i) ); EXPECT_EQ( "real", P_CAST(b, r) ); EXPECT_EQ( "string", P_CAST(b, s) ); EXPECT_EQ( "array", P_CAST(b, a) ); }
TYPED_TEST_P(TestCast, priority_cast_empty) { EXPECT_EQ( "null", P_CAST(n, n) ); EXPECT_EQ( "boolean", P_CAST(n, b) ); EXPECT_EQ( "integer", P_CAST(n, i) ); EXPECT_EQ( "real", P_CAST(n, r) ); EXPECT_EQ( "string", P_CAST(n, s) ); EXPECT_EQ( "array", P_CAST(n, a) ); }
TYPED_TEST_P(TestCast, priority_cast_array) { EXPECT_EQ( "array", P_CAST(a, n) ); EXPECT_EQ( "array", P_CAST(a, b) ); EXPECT_EQ( "array", P_CAST(a, i) ); EXPECT_EQ( "array", P_CAST(a, r) ); EXPECT_EQ( "array", P_CAST(a, s) ); EXPECT_EQ( "array", P_CAST(a, a) ); }
TYPED_TEST_P(TestCast, priority_cast_string) { EXPECT_EQ( "string", P_CAST(s, n) ); EXPECT_EQ( "string", P_CAST(s, b) ); EXPECT_EQ( "string", P_CAST(s, i) ); EXPECT_EQ( "string", P_CAST(s, r) ); EXPECT_EQ( "string", P_CAST(s, s) ); EXPECT_EQ( "array", P_CAST(s, a) ); }
TYPED_TEST_P(TestCast, priority_cast_real) { EXPECT_EQ( "real", P_CAST(r, n) ); EXPECT_EQ( "real", P_CAST(r, b) ); EXPECT_EQ( "real", P_CAST(r, i) ); EXPECT_EQ( "real", P_CAST(r, r) ); EXPECT_EQ( "string", P_CAST(r, s) ); EXPECT_EQ( "array", P_CAST(r, a) ); }
static TREE_IT_CALLBK(prune) { TREE_OBJ(struct tex_tr, p, tnd); P_CAST(n_pruned, uint32_t, pa_extra); BOOL res; if (p->tnd.sons.now == NULL /* is leaf */ && NULL != p->tnd.father /* can be pruned */) { /* prune ... */ if (p->n_fan == 0 /* grouped nodes */ || p->token_id == T_NIL /* nil nodes */) { res = tree_detach(&p->tnd, pa_now, pa_fwd); tex_tr_release(p); ++(*n_pruned); return res; } } LIST_GO_OVER; }
static TREE_IT_CALLBK(print) { TREE_OBJ(struct tex_tr, p, tnd); P_CAST(fh, FILE, pa_extra); int i; BOOL is_leaf; if (p->tnd.sons.now == NULL /* is leaf */) is_leaf = 1; else is_leaf = 0; if (pa_now->now == pa_head->last) depth_flag[pa_depth] = depth_going_end; else if (pa_now->now == pa_head->now) depth_flag[pa_depth] = depth_begin; for (i = 0; i<pa_depth; i++) { switch (depth_flag[i + 1]) { case depth_end: fprintf(fh, " "); break; case depth_begin: fprintf(fh, " │"); break; case depth_going_end: fprintf(fh, " └"); break; default: break; } } if (is_leaf) fprintf(fh, "──["); else fprintf(fh, "──("); #if (DEBUG_TEX_TR_PRINT_ID) fprintf(fh, "s%d, t%d, #%d, *%d, @%d", p->symbol_id, p->token_id, p->node_id, p->n_fan, p->rank); #else fprintf(fh, "%s, %s, #%d, *%d, @%d", trans_symbol(p->symbol_id), trans_token(p->token_id), p->node_id, p->n_fan, p->rank); #endif if (is_leaf) fprintf(fh, "]"); else fprintf(fh, ")"); if (p->n_fan == 0 && is_leaf) fprintf(fh, " (grouped)"); fprintf(fh, "\n"); if (depth_flag[pa_depth] == depth_going_end) depth_flag[pa_depth] = depth_end; LIST_GO_OVER; }
static LIST_IT_CALLBK(_posting_write) { LIST_OBJ(struct subpath, p, ln); P_CAST(id, CP_ID, pa_extra); char path[MAX_DIR_NAME_LEN]; FILE *fh; struct posting_head hd = {0, 0}; BOOL wr_flag = 0; /* make directory first */ sprintf(path, "col/%s", p->dir); mkdir_p(path); /* wirte posting header */ // sprintf(path, "col/%s/head.bin", p->dir); // // if(!file_exists(path)) { // /* the file does not exist currently. */ // fh = fopen(path, "w"); // // if (fh) { // hd.max = *id; // hd.min = *id; // // fwrite(&hd, sizeof(struct posting_head), 1, fh); // fclose(fh); // } // } else { // fh = fopen(path, "r+"); // if (fh) { // fread(&hd, sizeof(struct posting_head), 1, fh); // // if (hd.max < *id) { // hd.max = *id; // wr_flag = 1; // } // // if (*id < hd.min) { // hd.min = *id; // wr_flag = 1; // } // // if (wr_flag) { // /* overwrite by new numbers */ // rewind(fh); // fwrite(&hd, sizeof(struct posting_head), 1, fh); // } // // fclose(fh); // } // } /* wirte posting file */ sprintf(path, "col/%s/posting.bin", p->dir); fh = fopen(path, "a"); if (fh) { struct posting_item it; it.id = *id; it.brw = p->brw; fwrite(&it, sizeof(struct posting_item), 1, fh); fclose(fh); } LIST_GO_OVER; }