static void test_Flip_Block_bulk(TestBatch *batch) { int32_t offset; for (offset = 0; offset <= 17; offset++) { int32_t len; for (len = 0; len <= 17; len++) { int i; int upper = offset + len - 1; BitVector *bit_vec = BitVec_new(0); BitVec_Flip_Block(bit_vec, offset, len); for (i = 0; i <= 17; i++) { if (i >= offset && i <= upper) { if (!BitVec_Get(bit_vec, i)) { break; } } else { if (BitVec_Get(bit_vec, i)) { break; } } } TEST_INT_EQ(batch, i, 18, "Flip_Block(%d, %d)", offset, len); DECREF(bit_vec); } } }
static void test_Set_and_Get(TestBatch *batch) { unsigned i, max; const uint32_t three = 3; const uint32_t seventeen = 17; BitVector *bit_vec = BitVec_new(8); BitVec_Set(bit_vec, three); TEST_TRUE(batch, BitVec_Get_Capacity(bit_vec) < seventeen, "set below cap"); BitVec_Set(bit_vec, seventeen); TEST_TRUE(batch, BitVec_Get_Capacity(bit_vec) > seventeen, "set above cap causes BitVector to grow"); for (i = 0, max = BitVec_Get_Capacity(bit_vec); i < max; i++) { if (i == three || i == seventeen) { TEST_TRUE(batch, BitVec_Get(bit_vec, i), "set/get %d", i); } else { TEST_FALSE(batch, BitVec_Get(bit_vec, i), "get %d", i); } } TEST_FALSE(batch, BitVec_Get(bit_vec, i), "out of range get"); DECREF(bit_vec); }
static void test_Set_and_Get(TestBatchRunner *runner) { const size_t three = 3; const size_t seventeen = 17; BitVector *bit_vec = BitVec_new(8); BitVec_Set(bit_vec, three); TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) < seventeen, "set below cap"); BitVec_Set(bit_vec, seventeen); TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) > seventeen, "set above cap causes BitVector to grow"); size_t i, max; for (i = 0, max = BitVec_Get_Capacity(bit_vec); i < max; i++) { if (i == three || i == seventeen) { TEST_TRUE(runner, BitVec_Get(bit_vec, i), "set/get %u", (unsigned)i); } else { TEST_FALSE(runner, BitVec_Get(bit_vec, i), "get %u", (unsigned)i); } } TEST_FALSE(runner, BitVec_Get(bit_vec, i), "out of range get"); DECREF(bit_vec); }
static int S_verify_logical_op(BitVector *bit_vec, BitVector *set_1, BitVector *set_2, int op) { int i; for (i = 0; i < 50; i++) { bool_t wanted; switch (op) { case OP_OR: wanted = BitVec_Get(set_1, i) || BitVec_Get(set_2, i); break; case OP_XOR: wanted = (!BitVec_Get(set_1, i)) != (!BitVec_Get(set_2, i)); break; case OP_AND: wanted = BitVec_Get(set_1, i) && BitVec_Get(set_2, i); break; case OP_AND_NOT: wanted = BitVec_Get(set_1, i) && (!BitVec_Get(set_2, i)); break; default: wanted = false; THROW(ERR, "unknown op: %d", op); } if (BitVec_Get(bit_vec, i) != wanted) { break; } } return i; }
void DefDelWriter_Delete_By_Term_IMP(DefaultDeletionsWriter *self, String *field, Obj *term) { DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self); for (uint32_t i = 0, max = VA_Get_Size(ivars->seg_readers); i < max; i++) { SegReader *seg_reader = (SegReader*)VA_Fetch(ivars->seg_readers, i); PostingListReader *plist_reader = (PostingListReader*)SegReader_Fetch( seg_reader, Class_Get_Name(POSTINGLISTREADER)); BitVector *bit_vec = (BitVector*)VA_Fetch(ivars->bit_vecs, i); PostingList *plist = plist_reader ? PListReader_Posting_List(plist_reader, field, term) : NULL; int32_t doc_id; int32_t num_zapped = 0; // Iterate through postings, marking each doc as deleted. if (plist) { while (0 != (doc_id = PList_Next(plist))) { num_zapped += !BitVec_Get(bit_vec, doc_id); BitVec_Set(bit_vec, doc_id); } if (num_zapped) { ivars->updated[i] = true; } DECREF(plist); } } }
void DefDelWriter_Delete_By_Query_IMP(DefaultDeletionsWriter *self, Query *query) { DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self); Compiler *compiler = Query_Make_Compiler(query, (Searcher*)ivars->searcher, Query_Get_Boost(query), false); for (uint32_t i = 0, max = VA_Get_Size(ivars->seg_readers); i < max; i++) { SegReader *seg_reader = (SegReader*)VA_Fetch(ivars->seg_readers, i); BitVector *bit_vec = (BitVector*)VA_Fetch(ivars->bit_vecs, i); Matcher *matcher = Compiler_Make_Matcher(compiler, seg_reader, false); if (matcher) { int32_t doc_id; int32_t num_zapped = 0; // Iterate through matches, marking each doc as deleted. while (0 != (doc_id = Matcher_Next(matcher))) { num_zapped += !BitVec_Get(bit_vec, doc_id); BitVec_Set(bit_vec, doc_id); } if (num_zapped) { ivars->updated[i] = true; } DECREF(matcher); } } DECREF(compiler); }
static void test_Mimic(TestBatch *batch) { int foo; for (foo = 0; foo <= 17; foo++) { int bar; for (bar = 0; bar <= 17; bar++) { int i; BitVector *foo_vec = BitVec_new(0); BitVector *bar_vec = BitVec_new(0); BitVec_Set(foo_vec, foo); BitVec_Set(bar_vec, bar); BitVec_Mimic(foo_vec, (Obj*)bar_vec); for (i = 0; i <= 17; i++) { if (BitVec_Get(foo_vec, i) && i != bar) { break; } } TEST_INT_EQ(batch, i, 18, "Mimic(%d, %d)", foo, bar); DECREF(foo_vec); DECREF(bar_vec); } } }
static void test_Flip(TestBatchRunner *runner) { BitVector *bit_vec = BitVec_new(0); unsigned i; for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } for (i = 0; i <= 20; i++) { TEST_TRUE(runner, BitVec_Get(bit_vec, i), "flip on %u", i); } TEST_FALSE(runner, BitVec_Get(bit_vec, i), "no flip %u", i); for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } for (i = 0; i <= 20; i++) { TEST_FALSE(runner, BitVec_Get(bit_vec, i), "flip off %u", i); } TEST_FALSE(runner, BitVec_Get(bit_vec, 21), "still no flip %u", i); DECREF(bit_vec); }
static void test_Flip(TestBatch *batch) { BitVector *bit_vec = BitVec_new(0); int i; for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } for (i = 0; i <= 20; i++) { TEST_TRUE(batch, BitVec_Get(bit_vec, i), "flip on %d", i); } TEST_FALSE(batch, BitVec_Get(bit_vec, i), "no flip %d", i); for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } for (i = 0; i <= 20; i++) { TEST_FALSE(batch, BitVec_Get(bit_vec, i), "flip off %d", i); } TEST_FALSE(batch, BitVec_Get(bit_vec, i), "still no flip %d", i); DECREF(bit_vec); }
static void test_Clone(TestBatch *batch) { int i; BitVector *self = BitVec_new(30); BitVector *twin; BitVec_Set(self, 2); BitVec_Set(self, 3); BitVec_Set(self, 10); BitVec_Set(self, 20); twin = BitVec_Clone(self); for (i = 0; i < 50; i++) { if (BitVec_Get(self, i) != BitVec_Get(twin, i)) { break; } } TEST_INT_EQ(batch, i, 50, "Clone"); TEST_INT_EQ(batch, BitVec_Count(twin), 4, "clone Count"); DECREF(self); DECREF(twin); }
static void test_Flip_Block_ascending(TestBatchRunner *runner) { BitVector *bit_vec = BitVec_new(0); for (unsigned i = 0; i <= 20; i++) { BitVec_Flip_Block(bit_vec, i, 21 - i); } for (unsigned i = 0; i <= 20; i++) { if (i % 2 == 0) { TEST_TRUE(runner, BitVec_Get(bit_vec, i), "Flip_Block ascending %u", i); } else { TEST_FALSE(runner, BitVec_Get(bit_vec, i), "Flip_Block ascending %u", i); } } DECREF(bit_vec); }
static void test_Clone(TestBatchRunner *runner) { BitVector *self = BitVec_new(30); BitVector *twin; BitVec_Set(self, 2); BitVec_Set(self, 3); BitVec_Set(self, 10); BitVec_Set(self, 20); twin = BitVec_Clone(self); size_t i; for (i = 0; i < 50; i++) { if (BitVec_Get(self, i) != BitVec_Get(twin, i)) { break; } } TEST_UINT_EQ(runner, i, 50, "Clone"); TEST_UINT_EQ(runner, BitVec_Count(twin), 4, "clone Count"); DECREF(self); DECREF(twin); }
static void test_Flip_Block_descending(TestBatchRunner *runner) { BitVector *bit_vec = BitVec_new(0); for (int i = 19; i >= 0; i--) { BitVec_Flip_Block(bit_vec, 1, (size_t)i); } for (unsigned i = 0; i <= 20; i++) { if (i % 2) { TEST_TRUE(runner, BitVec_Get(bit_vec, i), "Flip_Block descending %u", i); } else { TEST_FALSE(runner, BitVec_Get(bit_vec, i), "Flip_Block descending %u", i); } } DECREF(bit_vec); }
void DefDelWriter_Delete_By_Doc_ID_IMP(DefaultDeletionsWriter *self, int32_t doc_id) { DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self); uint32_t sub_tick = PolyReader_sub_tick(ivars->seg_starts, doc_id); BitVector *bit_vec = (BitVector*)VA_Fetch(ivars->bit_vecs, sub_tick); uint32_t offset = I32Arr_Get(ivars->seg_starts, sub_tick); int32_t seg_doc_id = doc_id - offset; if (!BitVec_Get(bit_vec, seg_doc_id)) { ivars->updated[sub_tick] = true; BitVec_Set(bit_vec, seg_doc_id); } }
static void test_Flip_Block_descending(TestBatch *batch) { BitVector *bit_vec = BitVec_new(0); int i; for (i = 19; i >= 0; i--) { BitVec_Flip_Block(bit_vec, 1, i); } for (i = 0; i <= 20; i++) { if (i % 2) { TEST_TRUE(batch, BitVec_Get(bit_vec, i), "Flip_Block descending %d", i); } else { TEST_FALSE(batch, BitVec_Get(bit_vec, i), "Flip_Block descending %d", i); } } DECREF(bit_vec); }
static void test_Flip_Block_bulk(TestBatchRunner *runner) { for (unsigned offset = 0; offset <= 17; offset++) { for (unsigned len = 0; len <= 17; len++) { int upper = (int)offset + (int)len - 1; BitVector *bit_vec = BitVec_new(0); BitVec_Flip_Block(bit_vec, offset, len); unsigned i; for (i = 0; i <= 17; i++) { if (i >= offset && (int)i <= upper) { if (!BitVec_Get(bit_vec, i)) { break; } } else { if (BitVec_Get(bit_vec, i)) { break; } } } TEST_UINT_EQ(runner, i, 18, "Flip_Block(%u, %u)", offset, len); DECREF(bit_vec); } } }
static void test_Mimic(TestBatchRunner *runner) { for (unsigned foo = 0; foo <= 17; foo++) { for (unsigned bar = 0; bar <= 17; bar++) { BitVector *foo_vec = BitVec_new(0); BitVector *bar_vec = BitVec_new(0); BitVec_Set(foo_vec, foo); BitVec_Set(bar_vec, bar); BitVec_Mimic(foo_vec, (Obj*)bar_vec); unsigned i; for (i = 0; i <= 17; i++) { if (BitVec_Get(foo_vec, i) && i != bar) { break; } } TEST_UINT_EQ(runner, i, 18, "Mimic(%u, %u)", foo, bar); DECREF(foo_vec); DECREF(bar_vec); } } }