Kouhei Sutou
null+****@clear*****
Sat Sep 26 13:45:28 JST 2015
Kouhei Sutou 2015-09-26 13:45:28 +0900 (Sat, 26 Sep 2015) New Revision: 01d4cd45ea4b044d05d0d27495fa6100bd340594 https://github.com/groonga/groonga/commit/01d4cd45ea4b044d05d0d27495fa6100bd340594 Message: Unify grn_posting and grn_ii_posting grn_posting is removed and grn_ii_posting is renamed to grn_posting. Because we can use uint32_t in groonga.h. Now we can define grn_ii_posting as grn_posting in groonga.h Modified files: include/groonga/groonga.h lib/db.c lib/expr.c lib/geo.c lib/grn_ii.h lib/ii.c lib/mrb/mrb_index_cursor.c lib/proc.c plugins/suggest/suggest.c test/unit/core/test-inverted-index.c Modified: include/groonga/groonga.h (+5 -5) =================================================================== --- include/groonga/groonga.h 2015-09-26 12:59:13 +0900 (54a3b01) +++ include/groonga/groonga.h 2015-09-26 13:45:28 +0900 (531ba38) @@ -577,11 +577,11 @@ GRN_API grn_obj *grn_table_cursor_table(grn_ctx *ctx, grn_table_cursor *tc); typedef struct { grn_id rid; - grn_id sid; - unsigned int pos; - unsigned int tf; - unsigned int weight; - unsigned int rest; + uint32_t sid; + uint32_t pos; + uint32_t tf; + uint32_t weight; + uint32_t rest; } grn_posting; GRN_API grn_obj *grn_index_cursor_open(grn_ctx *ctx, grn_table_cursor *tc, grn_obj *index, Modified: lib/db.c (+8 -8) =================================================================== --- lib/db.c 2015-09-26 12:59:13 +0900 (5edcfdc) +++ lib/db.c 2015-09-26 13:45:28 +0900 (4b6f69d) @@ -1594,7 +1594,7 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id, { grn_ii *ii = (grn_ii *)index; grn_ii_cursor *ii_cursor = NULL; - grn_ii_posting *posting; + grn_posting *posting; grn_obj source_ids; unsigned int i, n_ids; grn_obj sources; @@ -2606,7 +2606,7 @@ grn_index_cursor_open(grn_ctx *ctx, grn_table_cursor *tc, grn_posting * grn_index_cursor_next(grn_ctx *ctx, grn_obj *c, grn_id *tid) { - grn_ii_posting *ip = NULL; + grn_posting *ip = NULL; grn_index_cursor *ic = (grn_index_cursor *)c; GRN_API_ENTER; if (ic->iic) { @@ -2843,7 +2843,7 @@ grn_accessor_resolve_one_index_column(grn_ctx *ctx, grn_accessor *accessor, { grn_obj_flags column_value_flags = 0; grn_obj column_value; - grn_ii_posting add_posting; + grn_posting add_posting; grn_id *tid; grn_rset_recinfo *recinfo; @@ -2928,7 +2928,7 @@ grn_accessor_resolve_one_data_column(grn_ctx *ctx, grn_accessor *accessor, GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &tid, NULL, &recinfo, { grn_ii *ii = (grn_ii *)index; grn_ii_cursor *ii_cursor; - grn_ii_posting *posting; + grn_posting *posting; ii_cursor = grn_ii_cursor_open(ctx, ii, *tid, GRN_ID_NIL, GRN_ID_MAX, @@ -2939,7 +2939,7 @@ grn_accessor_resolve_one_data_column(grn_ctx *ctx, grn_accessor *accessor, } while ((posting = grn_ii_cursor_next(ctx, ii_cursor))) { - grn_ii_posting add_posting = *posting; + grn_posting add_posting = *posting; add_posting.weight += recinfo->score - 1; rc = grn_ii_posting_add(ctx, &add_posting, @@ -3089,7 +3089,7 @@ grn_obj_search_accessor(grn_ctx *ctx, grn_obj *obj, grn_obj *query, grn_rset_recinfo *recinfo; GRN_HASH_EACH(ctx, (grn_hash *)resolve_res, id, &record_id, NULL, &recinfo, { - grn_ii_posting posting; + grn_posting posting; posting.rid = *record_id; posting.sid = 1; posting.pos = 0; @@ -3120,7 +3120,7 @@ grn_obj_search_column_index_by_id(grn_ctx *ctx, grn_obj *obj, c = grn_ii_cursor_open(ctx, (grn_ii *)obj, tid, GRN_ID_NIL, GRN_ID_MAX, 1, 0); if (c) { - grn_ii_posting *pos; + grn_posting *pos; grn_hash *s = (grn_hash *)res; while ((pos = grn_ii_cursor_next(ctx, c))) { /* todo: support orgarg(op) @@ -11024,7 +11024,7 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, while (i < e && (tid = grn_pat_cursor_next(ctx, pc))) { grn_ii_cursor *ic = grn_ii_cursor_open(ctx, (grn_ii *)index, tid, 0, 0, 1, 0); if (ic) { - grn_ii_posting *posting; + grn_posting *posting; while (i < e && (posting = grn_ii_cursor_next(ctx, ic))) { if (offset <= i) { grn_id *v; Modified: lib/expr.c (+6 -8) =================================================================== --- lib/expr.c 2015-09-26 12:59:13 +0900 (e3f3816) +++ lib/expr.c 2015-09-26 13:45:28 +0900 (9be2431) @@ -4871,11 +4871,9 @@ grn_table_select_index_range_column(grn_ctx *ctx, grn_obj *table, grn_posting *posting; while ((posting = grn_index_cursor_next(ctx, index_cursor, NULL))) { if (sid == 0 || posting->sid == sid) { - grn_ii_posting ii_posting; - ii_posting.rid = posting->rid; - ii_posting.sid = posting->sid; - ii_posting.weight = posting->weight * weight; - grn_ii_posting_add(ctx, &ii_posting, (grn_hash *)res, logical_op); + grn_posting new_posting = *posting; + new_posting.weight *= weight; + grn_ii_posting_add(ctx, &new_posting, (grn_hash *)res, logical_op); } } processed = GRN_TRUE; @@ -5106,7 +5104,7 @@ grn_table_select_index(grn_ctx *ctx, grn_obj *table, scan_info *si, !((grn_accessor *)index)->next) { grn_obj dest; grn_accessor *a = (grn_accessor *)index; - grn_ii_posting posting; + grn_posting posting; posting.sid = 1; posting.pos = 0; posting.weight = 0; @@ -5187,7 +5185,7 @@ grn_table_select_index(grn_ctx *ctx, grn_obj *table, scan_info *si, !((grn_accessor *)index)->next) { grn_obj dest; grn_accessor *a = (grn_accessor *)index; - grn_ii_posting posting; + grn_posting posting; posting.sid = 1; posting.pos = 0; posting.weight = 0; @@ -6960,7 +6958,7 @@ grn_column_filter(grn_ctx *ctx, grn_obj *column, grn_operator set_operation) { uint32_t *vp; - grn_ii_posting posting; + grn_posting posting; uint32_t value_ = grn_atoui(GRN_TEXT_VALUE(value), GRN_BULK_CURR(value), NULL); posting.sid = 1; posting.pos = 0; Modified: lib/geo.c (+9 -9) =================================================================== --- lib/geo.c 2015-09-26 12:59:13 +0900 (d2eb049) +++ lib/geo.c 2015-09-26 13:45:28 +0900 (d94419d) @@ -280,7 +280,7 @@ grn_geo_table_sort_detect_far_point(grn_ctx *ctx, grn_obj *table, grn_obj *index while ((tid = grn_pat_cursor_next(ctx, pc))) { grn_ii_cursor *ic = grn_ii_cursor_open(ctx, (grn_ii *)index, tid, 0, 0, 1, 0); if (ic) { - grn_ii_posting *posting; + grn_posting *posting; grn_gton(geo_key_prev, &point, sizeof(grn_geo_point)); grn_pat_get_key(ctx, pat, tid, &point, sizeof(grn_geo_point)); grn_gton(geo_key_curr, &point, sizeof(grn_geo_point)); @@ -553,7 +553,7 @@ grn_geo_table_sort_collect_points(grn_ctx *ctx, grn_obj *table, grn_obj *index, if (ic) { double d; grn_geo_point pos; - grn_ii_posting *posting; + grn_posting *posting; grn_pat_get_key(ctx, pat, tid, &pos, sizeof(grn_geo_point)); d = grn_geo_distance_rectangle_raw(ctx, base_point, &pos); inspect_tid(ctx, tid, &pos, d); @@ -704,7 +704,7 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, while (i < e && (tid = grn_pat_cursor_next(ctx, pc))) { grn_ii_cursor *ic = grn_ii_cursor_open(ctx, (grn_ii *)index, tid, 0, 0, 1, 0); if (ic) { - grn_ii_posting *posting; + grn_posting *posting; while (i < e && (posting = grn_ii_cursor_next(ctx, ic))) { if (offset <= i) { grn_id *v; @@ -1788,7 +1788,7 @@ grn_geo_cursor_entry_next(grn_ctx *ctx, return GRN_TRUE; } -typedef grn_bool (*grn_geo_cursor_callback)(grn_ctx *ctx, grn_ii_posting *posting, void *user_data); +typedef grn_bool (*grn_geo_cursor_callback)(grn_ctx *ctx, grn_posting *posting, void *user_data); static void grn_geo_cursor_each(grn_ctx *ctx, grn_obj *geo_cursor, @@ -1799,7 +1799,7 @@ grn_geo_cursor_each(grn_ctx *ctx, grn_obj *geo_cursor, grn_table_cursor *pat_cursor; grn_ii *ii; grn_ii_cursor *ii_cursor; - grn_ii_posting *posting = NULL; + grn_posting *posting = NULL; grn_geo_point *current, *top_left, *bottom_right; grn_id index_id; @@ -1886,10 +1886,10 @@ grn_geo_cursor_each(grn_ctx *ctx, grn_obj *geo_cursor, } static grn_bool -grn_geo_cursor_next_callback(grn_ctx *ctx, grn_ii_posting *posting, +grn_geo_cursor_next_callback(grn_ctx *ctx, grn_posting *posting, void *user_data) { - grn_ii_posting **return_posting = user_data; + grn_posting **return_posting = user_data; *return_posting = posting; return GRN_FALSE; } @@ -1897,7 +1897,7 @@ grn_geo_cursor_next_callback(grn_ctx *ctx, grn_ii_posting *posting, grn_posting * grn_geo_cursor_next(grn_ctx *ctx, grn_obj *geo_cursor) { - grn_ii_posting *posting = NULL; + grn_posting *posting = NULL; grn_geo_cursor_each(ctx, geo_cursor, grn_geo_cursor_next_callback, &posting); return (grn_posting *)posting; } @@ -1925,7 +1925,7 @@ typedef struct { } grn_geo_select_in_rectangle_data; static grn_bool -grn_geo_select_in_rectangle_callback(grn_ctx *ctx, grn_ii_posting *posting, +grn_geo_select_in_rectangle_callback(grn_ctx *ctx, grn_posting *posting, void *user_data) { grn_geo_select_in_rectangle_data *data = user_data; Modified: lib/grn_ii.h (+3 -12) =================================================================== --- lib/grn_ii.h 2015-09-26 12:59:13 +0900 (1ac9528) +++ lib/grn_ii.h 2015-09-26 13:45:28 +0900 (10c7e5b) @@ -107,26 +107,17 @@ int grn_ii_updspec_cmp(grn_ii_updspec *a, grn_ii_updspec *b); void grn_ii_expire(grn_ctx *ctx, grn_ii *ii); grn_rc grn_ii_flush(grn_ctx *ctx, grn_ii *ii); -typedef struct { - grn_id rid; - uint32_t sid; - uint32_t pos; - uint32_t tf; - uint32_t weight; - uint32_t rest; -} grn_ii_posting; - typedef struct _grn_ii_cursor grn_ii_cursor; -GRN_API grn_rc grn_ii_posting_add(grn_ctx *ctx, grn_ii_posting *pos, +GRN_API grn_rc grn_ii_posting_add(grn_ctx *ctx, grn_posting *pos, grn_hash *s, grn_operator op); GRN_API grn_ii_cursor *grn_ii_cursor_open(grn_ctx *ctx, grn_ii *ii, grn_id tid, grn_id min, grn_id max, int nelements, int flags); grn_ii_cursor *grn_ii_cursor_openv1(grn_ii *ii, uint32_t key); grn_rc grn_ii_cursor_openv2(grn_ii_cursor **cursors, int ncursors); -GRN_API grn_ii_posting *grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c); -grn_ii_posting *grn_ii_cursor_next_pos(grn_ctx *ctx, grn_ii_cursor *c); +GRN_API grn_posting *grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c); +grn_posting *grn_ii_cursor_next_pos(grn_ctx *ctx, grn_ii_cursor *c); GRN_API grn_rc grn_ii_cursor_close(grn_ctx *ctx, grn_ii_cursor *c); uint32_t grn_ii_max_section(grn_ii *ii); Modified: lib/ii.c (+16 -16) =================================================================== --- lib/ii.c 2015-09-26 12:59:13 +0900 (fc90ce7) +++ lib/ii.c 2015-09-26 13:45:28 +0900 (f4ddb67) @@ -3973,12 +3973,12 @@ struct _grn_ii_cursor { grn_ctx *ctx; grn_ii *ii; grn_id id; - grn_ii_posting *post; + grn_posting *post; grn_id min; grn_id max; - grn_ii_posting pc; - grn_ii_posting pb; + grn_posting pc; + grn_posting pb; uint32_t cdf; uint32_t *cdp; @@ -4184,7 +4184,7 @@ grn_ii_cursor_set_min(grn_ctx *ctx, grn_ii_cursor *c, grn_id min) } } -grn_ii_posting * +grn_posting * grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c) { if (c->buf) { @@ -4394,7 +4394,7 @@ grn_ii_cursor_next(grn_ctx *ctx, grn_ii_cursor *c) return c->post; } -grn_ii_posting * +grn_posting * grn_ii_cursor_next_pos(grn_ctx *ctx, grn_ii_cursor *c) { uint32_t gap; @@ -5359,7 +5359,7 @@ typedef struct { int pos; int size; int ntoken; - grn_ii_posting *p; + grn_posting *p; } token_info; #define EX_NONE 0 @@ -5499,7 +5499,7 @@ token_info_open(grn_ctx *ctx, grn_obj *lexicon, grn_ii *ii, { grn_ii_cursor *ic; if (ti->cursors && (ic = cursor_heap_min(ti->cursors))) { - grn_ii_posting *p = ic->post; + grn_posting *p = ic->post; ti->pos = p->pos - ti->offset; ti->p = p; } else { @@ -5514,7 +5514,7 @@ static inline grn_rc token_info_skip(grn_ctx *ctx, token_info *ti, uint32_t rid, uint32_t sid) { grn_ii_cursor *c; - grn_ii_posting *p; + grn_posting *p; for (;;) { if (!(c = cursor_heap_min(ti->cursors))) { return GRN_END_OF_DATA; } p = c->post; @@ -5530,7 +5530,7 @@ static inline grn_rc token_info_skip_pos(grn_ctx *ctx, token_info *ti, uint32_t rid, uint32_t sid, uint32_t pos) { grn_ii_cursor *c; - grn_ii_posting *p; + grn_posting *p; pos += ti->offset; for (;;) { if (!(c = cursor_heap_min(ti->cursors))) { return GRN_END_OF_DATA; } @@ -5701,7 +5701,7 @@ res_add(grn_ctx *ctx, grn_hash *s, grn_rset_posinfo *pi, double score, } grn_rc -grn_ii_posting_add(grn_ctx *ctx, grn_ii_posting *pos, grn_hash *s, grn_operator op) +grn_ii_posting_add(grn_ctx *ctx, grn_posting *pos, grn_hash *s, grn_operator op) { res_add(ctx, s, (grn_rset_posinfo *)(pos), (1 + pos->weight), op); return ctx->rc; @@ -5912,7 +5912,7 @@ grn_ii_similar_search(grn_ctx *ctx, grn_ii *ii, grn_id j, id; int w2, rep; grn_ii_cursor *c; - grn_ii_posting *pos; + grn_posting *pos; grn_wv_mode wvm = grn_wv_none; grn_table_sort_optarg arg = { GRN_TABLE_SORT_DESC|GRN_TABLE_SORT_BY_VALUE|GRN_TABLE_SORT_AS_NUMBER, @@ -5988,7 +5988,7 @@ grn_ii_term_extract(grn_ctx *ctx, grn_ii *ii, const char *string, const char *normalized; unsigned int normalized_length_in_bytes; grn_ii_cursor *c; - grn_ii_posting *pos; + grn_posting *pos; int skip, rep, policy; grn_rc rc = GRN_SUCCESS; grn_wv_mode wvm = grn_wv_none; @@ -6427,7 +6427,7 @@ grn_ii_select(grn_ctx *ctx, grn_ii *ii, const char *string, unsigned int string_ if ((rc = grn_hash_array_init(s, (*tis)->size + 32768))) { goto exit; } do { grn_rset_recinfo *ri; - grn_ii_posting *p = c->post; + grn_posting *p = c->post; if ((weight = get_weight(ctx, s, p->rid, p->sid, wvm, optarg))) { GRN_HASH_INT_ADD(s, p, ri); ri->score = (p->tf + p->score) * weight; @@ -6815,7 +6815,7 @@ grn_ii_at(grn_ctx *ctx, grn_ii *ii, grn_id id, grn_hash *s, grn_operator op) { int rep = 0; grn_ii_cursor *c; - grn_ii_posting *pos; + grn_posting *pos; if ((c = grn_ii_cursor_open(ctx, ii, id, GRN_ID_NIL, GRN_ID_MAX, rep ? ii->n_elements : ii->n_elements - 1, 0))) { while ((pos = grn_ii_cursor_next(ctx, c))) { @@ -6849,7 +6849,7 @@ grn_ii_resolve_sel_and(grn_ctx *ctx, grn_hash *s, grn_operator op) } /* just for inspect */ -static grn_ii_posting * +static grn_posting * grn_ii_cursor_next_all(grn_ctx *ctx, grn_ii_cursor *c) { if (c->buf) { @@ -7050,7 +7050,7 @@ grn_ii_cursor_inspect(grn_ctx *ctx, grn_ii_cursor *c, grn_obj *buf) GRN_TEXT_PUTS(ctx, buf, "\n elements:[\n "); while (grn_ii_cursor_next_all(ctx, c)) { - grn_ii_posting *pos = c->post; + grn_posting *pos = c->post; if (i > 0) { GRN_TEXT_PUTS(ctx, buf, ",\n "); } Modified: lib/mrb/mrb_index_cursor.c (+1 -1) =================================================================== --- lib/mrb/mrb_index_cursor.c 2015-09-26 12:59:13 +0900 (bcfa0de) +++ lib/mrb/mrb_index_cursor.c 2015-09-26 13:45:28 +0900 (c99eae0) @@ -190,7 +190,7 @@ mrb_grn_index_cursor_select(mrb_state *mrb, mrb_value self) offset--; continue; } - grn_ii_posting_add(ctx, (grn_ii_posting *)posting, result_set, op); + grn_ii_posting_add(ctx, posting, result_set, op); limit--; if (limit == 0) { break; Modified: lib/proc.c (+5 -10) =================================================================== --- lib/proc.c 2015-09-26 12:59:13 +0900 (fea5e50) +++ lib/proc.c 2015-09-26 13:45:28 +0900 (020d28b) @@ -4936,9 +4936,9 @@ selector_all_records(grn_ctx *ctx, grn_obj *table, grn_obj *index, int nargs, grn_obj **args, grn_obj *res, grn_operator op) { - grn_ii_posting posting; + grn_posting posting; - memset(&posting, 0, sizeof(grn_ii_posting)); + memset(&posting, 0, sizeof(grn_posting)); GRN_TABLE_EACH(ctx, table, 0, 0, id, NULL, NULL, NULL, { posting.rid = id; grn_ii_posting_add(ctx, &posting, (grn_hash *)res, GRN_OP_OR); @@ -5898,7 +5898,7 @@ selector_between_sequential_search(grn_ctx *ctx, grn_bool result_boolean; GRN_TRUEP(ctx, result, result_boolean); if (result_boolean) { - grn_ii_posting posting; + grn_posting posting; posting.rid = record_id; posting.sid = 1; posting.pos = 0; @@ -6468,7 +6468,7 @@ selector_in_values_sequential_search(grn_ctx *ctx, for (i = 0; i < n_value_ids; i++) { grn_id value_id = GRN_RECORD_VALUE_AT(&value_ids, i); if (value_id == GRN_RECORD_VALUE(&record_value)) { - grn_ii_posting posting; + grn_posting posting; posting.rid = record_id; posting.sid = 1; posting.pos = 0; @@ -6748,12 +6748,7 @@ proc_range_filter(grn_ctx *ctx, int nargs, grn_obj **args, if (result_boolean) { if (n_records >= real_offset) { - grn_ii_posting ii_posting; - ii_posting.rid = posting->rid; - ii_posting.sid = posting->sid; - ii_posting.pos = posting->pos; - ii_posting.weight = posting->weight; - grn_ii_posting_add(ctx, &ii_posting, (grn_hash *)res, op); + grn_ii_posting_add(ctx, posting, (grn_hash *)res, op); } n_records++; if (n_records == real_limit) { Modified: plugins/suggest/suggest.c (+2 -2) =================================================================== --- plugins/suggest/suggest.c 2015-09-26 12:59:13 +0900 (7a11208) +++ plugins/suggest/suggest.c 2015-09-26 13:45:28 +0900 (07a8689) @@ -159,7 +159,7 @@ cooccurrence_search(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost, grn_id i } if ((c = grn_ii_cursor_open(ctx, (grn_ii *)co, id, GRN_ID_NIL, GRN_ID_MAX, ((grn_ii *)co)->n_elements - 1, 0))) { - grn_ii_posting *p; + grn_posting *p; grn_obj post, pair_freq, item_freq, item_freq2, item_boost; GRN_RECORD_INIT(&post, 0, grn_obj_id(ctx, items)); GRN_INT32_INIT(&pair_freq, 0); @@ -323,7 +323,7 @@ complete(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost, grn_obj *col, grn_ii_cursor *icur; if ((icur = grn_ii_cursor_open(ctx, (grn_ii *)index, id, GRN_ID_NIL, GRN_ID_MAX, 1, 0))) { - grn_ii_posting *p; + grn_posting *p; while ((p = grn_ii_cursor_next(ctx, icur))) { complete_add_item(ctx, p->rid, res, frequency_threshold, items_freq, items_boost, Modified: test/unit/core/test-inverted-index.c (+1 -1) =================================================================== --- test/unit/core/test-inverted-index.c 2015-09-26 12:59:13 +0900 (b19dfd1) +++ test/unit/core/test-inverted-index.c 2015-09-26 13:45:28 +0900 (eb2570c) @@ -367,7 +367,7 @@ retrieve_record_ids(const gchar *term) { grn_id term_id; grn_ii_cursor *cursor; - grn_ii_posting *posting; + grn_posting *posting; term_id = grn_table_get(context, lexicon, term, strlen(term)); if (term_id == GRN_ID_NIL) -------------- next part -------------- HTML����������������������������...다운로드