LexiconWriter* LexWriter_init(LexiconWriter *self, Snapshot *snapshot, Segment *segment, PolyReader *polyreader) { Schema *schema = PolyReader_Get_Schema(polyreader); Architecture *arch = Schema_Get_Architecture(schema); DataWriter_init((DataWriter*)self, snapshot, segment, polyreader); /* Assign. */ self->index_interval = Arch_Index_Interval(arch); self->skip_interval = Arch_Skip_Interval(arch); /* Init. */ self->ix_out = NULL; self->ixix_out = NULL; self->dat_out = NULL; self->count = 0; self->ix_count = 0; self->last_tinfo = TInfo_new(0,0,0,0); self->last_text = CB_new(40); self->dat_file = CB_new(30); self->ix_file = CB_new(30); self->ixix_file = CB_new(30); self->counts = Hash_new(0); self->ix_counts = Hash_new(0); self->stepper = NULL; self->temp_mode = false; /* Derive. */ self->stepper = LexStepper_new((CharBuf*)&EMPTY, self->skip_interval); return self; }
LexiconWriter* LexWriter_init(LexiconWriter *self, Schema *schema, Snapshot *snapshot, Segment *segment, PolyReader *polyreader) { Architecture *arch = Schema_Get_Architecture(schema); DataWriter_init((DataWriter*)self, schema, snapshot, segment, polyreader); // Assign. self->index_interval = Arch_Index_Interval(arch); self->skip_interval = Arch_Skip_Interval(arch); // Init. self->ix_out = NULL; self->ixix_out = NULL; self->dat_out = NULL; self->count = 0; self->ix_count = 0; self->dat_file = CB_new(30); self->ix_file = CB_new(30); self->ixix_file = CB_new(30); self->counts = Hash_new(0); self->ix_counts = Hash_new(0); self->temp_mode = false; self->term_stepper = NULL; self->tinfo_stepper = (TermStepper*)MatchTInfoStepper_new(schema); return self; }
LexIndex* LexIndex_init(LexIndex *self, Schema *schema, Folder *folder, Segment *segment, String *field) { int32_t field_num = Seg_Field_Num(segment, field); String *seg_name = Seg_Get_Name(segment); String *ixix_file = Str_newf("%o/lexicon-%i32.ixix", seg_name, field_num); String *ix_file = Str_newf("%o/lexicon-%i32.ix", seg_name, field_num); Architecture *arch = Schema_Get_Architecture(schema); // Init. Lex_init((Lexicon*)self, field); LexIndexIVARS *const ivars = LexIndex_IVARS(self); ivars->tinfo = TInfo_new(0); ivars->tick = 0; // Derive ivars->field_type = Schema_Fetch_Type(schema, field); if (!ivars->field_type) { String *mess = MAKE_MESS("Unknown field: '%o'", field); DECREF(ix_file); DECREF(ixix_file); DECREF(self); Err_throw_mess(ERR, mess); } ivars->field_type = (FieldType*)INCREF(ivars->field_type); ivars->term_stepper = FType_Make_Term_Stepper(ivars->field_type); ivars->ixix_in = Folder_Open_In(folder, ixix_file); if (!ivars->ixix_in) { Err *error = (Err*)INCREF(Err_get_error()); DECREF(ix_file); DECREF(ixix_file); DECREF(self); RETHROW(error); } ivars->ix_in = Folder_Open_In(folder, ix_file); if (!ivars->ix_in) { Err *error = (Err*)INCREF(Err_get_error()); DECREF(ix_file); DECREF(ixix_file); DECREF(self); RETHROW(error); } ivars->index_interval = Arch_Index_Interval(arch); ivars->skip_interval = Arch_Skip_Interval(arch); ivars->size = (int32_t)(InStream_Length(ivars->ixix_in) / sizeof(int64_t)); ivars->offsets = (const int64_t*)InStream_Buf(ivars->ixix_in, (size_t)InStream_Length(ivars->ixix_in)); DECREF(ixix_file); DECREF(ix_file); return self; }
LexIndex* LexIndex_init(LexIndex *self, Schema *schema, Folder *folder, Segment *segment, const CharBuf *field) { i32_t field_num = Seg_Field_Num(segment, field); CharBuf *seg_name = Seg_Get_Name(segment); CharBuf *ixix_file = CB_newf("%o/lexicon-%i32.ixix", seg_name, field_num); CharBuf *ix_file = CB_newf("%o/lexicon-%i32.ix", seg_name, field_num); Architecture *arch = Schema_Get_Architecture(schema); /* Init. */ self->term = ViewCB_new_from_trusted_utf8(NULL, 0); self->tinfo = TInfo_new(0,0,0,0); self->tick = 0; /* Derive */ self->field_type = Schema_Fetch_Type(schema, field); if (!self->field_type) { CharBuf *mess = MAKE_MESS("Unknown field: '%o'", field); DECREF(ix_file); DECREF(ixix_file); DECREF(self); Err_throw_mess(mess); } INCREF(self->field_type); self->ixix_in = Folder_Open_In(folder, ixix_file); self->ix_in = Folder_Open_In(folder, ix_file); if (!self->ixix_in || !self->ix_in) { CharBuf *mess = MAKE_MESS("Can't open either %o or %o", ix_file, ixix_file); DECREF(ix_file); DECREF(ixix_file); DECREF(self); Err_throw_mess(mess); } self->index_interval = Arch_Index_Interval(arch); self->skip_interval = Arch_Skip_Interval(arch); self->size = (i32_t)(InStream_Length(self->ixix_in) / sizeof(i64_t)); self->offsets = (i64_t*)InStream_Buf(self->ixix_in, (size_t)InStream_Length(self->ixix_in)); self->data = InStream_Buf(self->ix_in, InStream_Length(self->ix_in)); self->limit = self->data + InStream_Length(self->ix_in); DECREF(ixix_file); DECREF(ix_file); return self; }