static void test_Mimic(TestBatch *batch) { Float32 *f32 = Float32_new(1.33f); Float64 *f64 = Float64_new(1.33); Integer32 *i32 = Int32_new(I32_MAX); Integer64 *i64 = Int64_new(I64_MAX); Float32 *f32_dupe = Float32_new(0.0f); Float64 *f64_dupe = Float64_new(0.0); Integer32 *i32_dupe = Int32_new(0); Integer64 *i64_dupe = Int64_new(0); Float32_Mimic(f32_dupe, (Obj*)f32); Float64_Mimic(f64_dupe, (Obj*)f64); Int32_Mimic(i32_dupe, (Obj*)i32); Int64_Mimic(i64_dupe, (Obj*)i64); TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f32_dupe), "Float32 Mimic"); TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f64_dupe), "Float64 Mimic"); TEST_TRUE(batch, Int32_Equals(i32, (Obj*)i32_dupe), "Integer32 Mimic"); TEST_TRUE(batch, Int64_Equals(i64, (Obj*)i64_dupe), "Integer64 Mimic"); DECREF(i64_dupe); DECREF(i32_dupe); DECREF(f64_dupe); DECREF(f32_dupe); DECREF(i64); DECREF(i32); DECREF(f64); DECREF(f32); }
static void test_Clone(TestBatch *batch) { Float32 *f32 = Float32_new(1.33f); Float64 *f64 = Float64_new(1.33); Integer32 *i32 = Int32_new(I32_MAX); Integer64 *i64 = Int64_new(I64_MAX); Float32 *f32_dupe = Float32_Clone(f32); Float64 *f64_dupe = Float64_Clone(f64); Integer32 *i32_dupe = Int32_Clone(i32); Integer64 *i64_dupe = Int64_Clone(i64); TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f32_dupe), "Float32 Clone"); TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f64_dupe), "Float64 Clone"); TEST_TRUE(batch, Int32_Equals(i32, (Obj*)i32_dupe), "Integer32 Clone"); TEST_TRUE(batch, Int64_Equals(i64, (Obj*)i64_dupe), "Integer64 Clone"); TEST_TRUE(batch, Bool_Equals(CFISH_TRUE, (Obj*)Bool_Clone(CFISH_TRUE)), "BoolNum Clone"); DECREF(i64_dupe); DECREF(i32_dupe); DECREF(f64_dupe); DECREF(f32_dupe); DECREF(i64); DECREF(i32); DECREF(f64); DECREF(f32); }
static void test_vcatf_obj(TestBatchRunner *runner) { String *wanted = S_get_str("ooga 20 booga"); Integer32 *i32 = Int32_new(20); CharBuf *got = S_get_cb("ooga"); CB_catf(got, " %o booga", i32); TEST_TRUE(runner, S_cb_equals(got, wanted), "%%o Obj"); DECREF(i32); DECREF(wanted); DECREF(got); }
static void test_vcatf_obj(TestBatch *batch) { CharBuf *wanted = S_get_cb("ooga 20 booga"); Integer32 *i32 = Int32_new(20); CharBuf *got = S_get_cb("ooga"); CB_catf(got, " %o booga", i32); TEST_TRUE(batch, CB_Equals(wanted, (Obj*)got), "%%o Obj"); DECREF(i32); DECREF(wanted); DECREF(got); }
int32_t Seg_add_field(Segment *self, const CharBuf *field) { Integer32 *num = (Integer32*)Hash_Fetch(self->by_name, (Obj*)field); if (num) { return Int32_Get_Value(num); } else { int32_t field_num = VA_Get_Size(self->by_num); Hash_Store(self->by_name, (Obj*)field, (Obj*)Int32_new(field_num)); VA_Push(self->by_num, (Obj*)CB_Clone(field)); return field_num; } }
InverterEntry* InvEntry_init(InverterEntry *self, Schema *schema, String *field, int32_t field_num) { InverterEntryIVARS *const ivars = InvEntry_IVARS(self); ivars->field_num = field_num; ivars->field = field ? Str_Clone(field) : NULL; ivars->inversion = NULL; if (schema) { ivars->analyzer = (Analyzer*)INCREF(Schema_Fetch_Analyzer(schema, field)); ivars->sim = (Similarity*)INCREF(Schema_Fetch_Sim(schema, field)); ivars->type = (FieldType*)INCREF(Schema_Fetch_Type(schema, field)); if (!ivars->type) { THROW(ERR, "Unknown field: '%o'", field); } uint8_t prim_id = FType_Primitive_ID(ivars->type); switch (prim_id & FType_PRIMITIVE_ID_MASK) { case FType_TEXT: ivars->value = NULL; break; case FType_BLOB: ivars->value = (Obj*)ViewBB_new(NULL, 0); break; case FType_INT32: ivars->value = (Obj*)Int32_new(0); break; case FType_INT64: ivars->value = (Obj*)Int64_new(0); break; case FType_FLOAT32: ivars->value = (Obj*)Float32_new(0); break; case FType_FLOAT64: ivars->value = (Obj*)Float64_new(0); break; default: THROW(ERR, "Unrecognized primitive id: %i8", prim_id); } ivars->indexed = FType_Indexed(ivars->type); if (ivars->indexed && FType_Is_A(ivars->type, NUMERICTYPE)) { THROW(ERR, "Field '%o' spec'd as indexed, but numerical types cannot " "be indexed yet", field); } if (FType_Is_A(ivars->type, FULLTEXTTYPE)) { ivars->highlightable = FullTextType_Highlightable((FullTextType*)ivars->type); } } return self; }
DefaultDeletionsWriter* DefDelWriter_init(DefaultDeletionsWriter *self, Schema *schema, Snapshot *snapshot, Segment *segment, PolyReader *polyreader) { DataWriter_init((DataWriter*)self, schema, snapshot, segment, polyreader); DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self); ivars->seg_readers = PolyReader_Seg_Readers(polyreader); uint32_t num_seg_readers = VA_Get_Size(ivars->seg_readers); ivars->seg_starts = PolyReader_Offsets(polyreader); ivars->bit_vecs = VA_new(num_seg_readers); ivars->updated = (bool*)CALLOCATE(num_seg_readers, sizeof(bool)); ivars->searcher = IxSearcher_new((Obj*)polyreader); ivars->name_to_tick = Hash_new(num_seg_readers); // Materialize a BitVector of deletions for each segment. for (uint32_t i = 0; i < num_seg_readers; i++) { SegReader *seg_reader = (SegReader*)VA_Fetch(ivars->seg_readers, i); BitVector *bit_vec = BitVec_new(SegReader_Doc_Max(seg_reader)); DeletionsReader *del_reader = (DeletionsReader*)SegReader_Fetch( seg_reader, Class_Get_Name(DELETIONSREADER)); Matcher *seg_dels = del_reader ? DelReader_Iterator(del_reader) : NULL; if (seg_dels) { int32_t del; while (0 != (del = Matcher_Next(seg_dels))) { BitVec_Set(bit_vec, del); } DECREF(seg_dels); } VA_Store(ivars->bit_vecs, i, (Obj*)bit_vec); Hash_Store(ivars->name_to_tick, (Obj*)SegReader_Get_Seg_Name(seg_reader), (Obj*)Int32_new(i)); } return self; }
static void test_To_String(TestBatch *batch) { Float32 *f32 = Float32_new(1.33f); Float64 *f64 = Float64_new(1.33); Integer32 *i32 = Int32_new(I32_MAX); Integer64 *i64 = Int64_new(I64_MAX); CharBuf *f32_string = Float32_To_String(f32); CharBuf *f64_string = Float64_To_String(f64); CharBuf *i32_string = Int32_To_String(i32); CharBuf *i64_string = Int64_To_String(i64); CharBuf *true_string = Bool_To_String(CFISH_TRUE); CharBuf *false_string = Bool_To_String(CFISH_FALSE); TEST_TRUE(batch, CB_Starts_With_Str(f32_string, "1.3", 3), "Float32_To_String"); TEST_TRUE(batch, CB_Starts_With_Str(f64_string, "1.3", 3), "Float64_To_String"); TEST_TRUE(batch, CB_Equals_Str(i32_string, "2147483647", 10), "Int32_To_String"); TEST_TRUE(batch, CB_Equals_Str(i64_string, "9223372036854775807", 19), "Int64_To_String"); TEST_TRUE(batch, CB_Equals_Str(true_string, "true", 4), "Bool_To_String [true]"); TEST_TRUE(batch, CB_Equals_Str(false_string, "false", 5), "Bool_To_String [false]"); DECREF(false_string); DECREF(true_string); DECREF(i64_string); DECREF(i32_string); DECREF(f64_string); DECREF(f32_string); DECREF(i64); DECREF(i32); DECREF(f64); DECREF(f32); }
Integer32* I32SortCache_make_blank(Int32SortCache *self) { UNUSED_VAR(self); return Int32_new(0); }
HitDoc* DefDocReader_Fetch_Doc_IMP(DefaultDocReader *self, int32_t doc_id) { DefaultDocReaderIVARS *const ivars = DefDocReader_IVARS(self); Schema *const schema = ivars->schema; InStream *const dat_in = ivars->dat_in; InStream *const ix_in = ivars->ix_in; Hash *const fields = Hash_new(1); int64_t start; uint32_t num_fields; uint32_t field_name_cap = 31; char *field_name = (char*)MALLOCATE(field_name_cap + 1); // Get data file pointer from index, read number of fields. InStream_Seek(ix_in, (int64_t)doc_id * 8); start = InStream_Read_U64(ix_in); InStream_Seek(dat_in, start); num_fields = InStream_Read_C32(dat_in); // Decode stored data and build up the doc field by field. while (num_fields--) { uint32_t field_name_len; Obj *value; FieldType *type; // Read field name. field_name_len = InStream_Read_C32(dat_in); if (field_name_len > field_name_cap) { field_name_cap = field_name_len; field_name = (char*)REALLOCATE(field_name, field_name_cap + 1); } InStream_Read_Bytes(dat_in, field_name, field_name_len); // Find the Field's FieldType. StackString *field_name_str = SSTR_WRAP_UTF8(field_name, field_name_len); type = Schema_Fetch_Type(schema, (String*)field_name_str); // Read the field value. switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) { case FType_TEXT: { uint32_t value_len = InStream_Read_C32(dat_in); char *buf = (char*)MALLOCATE(value_len + 1); InStream_Read_Bytes(dat_in, buf, value_len); buf[value_len] = '\0'; value = (Obj*)Str_new_steal_utf8(buf, value_len); break; } case FType_BLOB: { uint32_t value_len = InStream_Read_C32(dat_in); char *buf = (char*)MALLOCATE(value_len); InStream_Read_Bytes(dat_in, buf, value_len); value = (Obj*)BB_new_steal_bytes( buf, value_len, value_len); break; } case FType_FLOAT32: value = (Obj*)Float32_new( InStream_Read_F32(dat_in)); break; case FType_FLOAT64: value = (Obj*)Float64_new( InStream_Read_F64(dat_in)); break; case FType_INT32: value = (Obj*)Int32_new( (int32_t)InStream_Read_C32(dat_in)); break; case FType_INT64: value = (Obj*)Int64_new( (int64_t)InStream_Read_C64(dat_in)); break; default: value = NULL; THROW(ERR, "Unrecognized type: %o", type); } // Store the value. Hash_Store_Utf8(fields, field_name, field_name_len, value); } FREEMEM(field_name); HitDoc *retval = HitDoc_new(fields, doc_id, 0.0); DECREF(fields); return retval; }
static void test_accessors(TestBatch *batch) { Float32 *f32 = Float32_new(1.0); Float64 *f64 = Float64_new(1.0); Integer32 *i32 = Int32_new(1); Integer64 *i64 = Int64_new(1); float wanted32 = 1.33f; double wanted64 = 1.33; float got32; double got64; Float32_Set_Value(f32, 1.33f); TEST_FLOAT_EQ(batch, Float32_Get_Value(f32), 1.33f, "F32 Set_Value Get_Value"); Float64_Set_Value(f64, 1.33); got64 = Float64_Get_Value(f64); TEST_TRUE(batch, *(int64_t*)&got64 == *(int64_t*)&wanted64, "F64 Set_Value Get_Value"); TEST_TRUE(batch, Float32_To_I64(f32) == 1, "Float32_To_I64"); TEST_TRUE(batch, Float64_To_I64(f64) == 1, "Float64_To_I64"); got32 = (float)Float32_To_F64(f32); TEST_TRUE(batch, *(int32_t*)&got32 == *(int32_t*)&wanted32, "Float32_To_F64"); got64 = Float64_To_F64(f64); TEST_TRUE(batch, *(int64_t*)&got64 == *(int64_t*)&wanted64, "Float64_To_F64"); Int32_Set_Value(i32, I32_MIN); TEST_INT_EQ(batch, Int32_Get_Value(i32), I32_MIN, "I32 Set_Value Get_Value"); Int64_Set_Value(i64, I64_MIN); TEST_TRUE(batch, Int64_Get_Value(i64) == I64_MIN, "I64 Set_Value Get_Value"); Int32_Set_Value(i32, -1); Int64_Set_Value(i64, -1); TEST_TRUE(batch, Int32_To_F64(i32) == -1, "Int32_To_F64"); TEST_TRUE(batch, Int64_To_F64(i64) == -1, "Int64_To_F64"); TEST_INT_EQ(batch, Bool_Get_Value(CFISH_TRUE), true, "Bool_Get_Value [true]"); TEST_INT_EQ(batch, Bool_Get_Value(CFISH_FALSE), false, "Bool_Get_Value [false]"); TEST_TRUE(batch, Bool_To_I64(CFISH_TRUE) == true, "Bool_To_I64 [true]"); TEST_TRUE(batch, Bool_To_I64(CFISH_FALSE) == false, "Bool_To_I64 [false]"); TEST_TRUE(batch, Bool_To_F64(CFISH_TRUE) == 1.0, "Bool_To_F64 [true]"); TEST_TRUE(batch, Bool_To_F64(CFISH_FALSE) == 0.0, "Bool_To_F64 [false]"); DECREF(i64); DECREF(i32); DECREF(f64); DECREF(f32); }
static void test_Equals_and_Compare_To(TestBatch *batch) { Float32 *f32 = Float32_new(1.0); Float64 *f64 = Float64_new(1.0); Integer32 *i32 = Int32_new(I32_MAX); Integer64 *i64 = Int64_new(I64_MAX); TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) == 0, "F32_Compare_To equal"); TEST_TRUE(batch, Float32_Equals(f32, (Obj*)f64), "F32_Equals equal"); Float64_Set_Value(f64, 2.0); TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) < 0, "F32_Compare_To less than"); TEST_FALSE(batch, Float32_Equals(f32, (Obj*)f64), "F32_Equals less than"); Float64_Set_Value(f64, 0.0); TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)f64) > 0, "F32_Compare_To greater than"); TEST_FALSE(batch, Float32_Equals(f32, (Obj*)f64), "F32_Equals greater than"); Float64_Set_Value(f64, 1.0); Float32_Set_Value(f32, 1.0); TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) == 0, "F64_Compare_To equal"); TEST_TRUE(batch, Float64_Equals(f64, (Obj*)f32), "F64_Equals equal"); Float32_Set_Value(f32, 2.0); TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) < 0, "F64_Compare_To less than"); TEST_FALSE(batch, Float64_Equals(f64, (Obj*)f32), "F64_Equals less than"); Float32_Set_Value(f32, 0.0); TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)f32) > 0, "F64_Compare_To greater than"); TEST_FALSE(batch, Float64_Equals(f64, (Obj*)f32), "F64_Equals greater than"); Float64_Set_Value(f64, I64_MAX * 2.0); TEST_TRUE(batch, Float64_Compare_To(f64, (Obj*)i64) > 0, "Float64 comparison to Integer64"); TEST_TRUE(batch, Int64_Compare_To(i64, (Obj*)f64) < 0, "Integer64 comparison to Float64"); Float32_Set_Value(f32, I32_MAX * 2.0f); TEST_TRUE(batch, Float32_Compare_To(f32, (Obj*)i32) > 0, "Float32 comparison to Integer32"); TEST_TRUE(batch, Int32_Compare_To(i32, (Obj*)f32) < 0, "Integer32 comparison to Float32"); Int64_Set_Value(i64, 0x6666666666666666LL); Integer64 *i64_copy = Int64_new(0x6666666666666666LL); TEST_TRUE(batch, Int64_Compare_To(i64, (Obj*)i64_copy) == 0, "Integer64 comparison to same number"); TEST_TRUE(batch, Bool_Equals(CFISH_TRUE, (Obj*)CFISH_TRUE), "CFISH_TRUE Equals itself"); TEST_TRUE(batch, Bool_Equals(CFISH_FALSE, (Obj*)CFISH_FALSE), "CFISH_FALSE Equals itself"); TEST_FALSE(batch, Bool_Equals(CFISH_FALSE, (Obj*)CFISH_TRUE), "CFISH_FALSE not Equals CFISH_TRUE "); TEST_FALSE(batch, Bool_Equals(CFISH_TRUE, (Obj*)CFISH_FALSE), "CFISH_TRUE not Equals CFISH_FALSE "); TEST_FALSE(batch, Bool_Equals(CFISH_TRUE, (Obj*)CHARBUF), "CFISH_TRUE not Equals random other object "); DECREF(i64_copy); DECREF(i64); DECREF(i32); DECREF(f64); DECREF(f32); }
Integer32* Int32_clone(Integer32 *self) { return Int32_new(self->value); }
Integer32* Int32_Clone_IMP(Integer32 *self) { return Int32_new(self->value); }