static ORMatcher* S_ormatcher_init2(ORMatcher *self, ORMatcherIVARS *ivars, Vector *children, Similarity *sim) { // Init. PolyMatcher_init((PolyMatcher*)self, children, sim); ivars->size = 0; // Derive. ivars->max_size = (uint32_t)Vec_Get_Size(children); // Allocate. ivars->heap = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*)); // Create a pool of HMDs. Encourage CPU cache hits by using a single // allocation for all of them. size_t amount_to_malloc = (ivars->max_size + 1) * sizeof(HeapedMatcherDoc); ivars->blob = (char*)MALLOCATE(amount_to_malloc); ivars->pool = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*)); for (uint32_t i = 1; i <= ivars->max_size; i++) { size_t offset = i * sizeof(HeapedMatcherDoc); HeapedMatcherDoc *hmd = (HeapedMatcherDoc*)(ivars->blob + offset); ivars->pool[i] = hmd; } // Prime queue. for (uint32_t i = 0; i < ivars->max_size; i++) { Matcher *matcher = (Matcher*)Vec_Fetch(children, i); if (matcher) { S_add_element(self, ivars, (Matcher*)INCREF(matcher), 0); } } return self; }
RequiredOptionalMatcher* ReqOptMatcher_init(RequiredOptionalMatcher *self, Similarity *similarity, Matcher *required_matcher, Matcher *optional_matcher) { VArray *children = VA_new(2); VA_Push(children, INCREF(required_matcher)); VA_Push(children, INCREF(optional_matcher)); PolyMatcher_init((PolyMatcher*)self, children, similarity); RequiredOptionalMatcherIVARS *const ivars = ReqOptMatcher_IVARS(self); // Assign. ivars->req_matcher = (Matcher*)INCREF(required_matcher); ivars->opt_matcher = (Matcher*)INCREF(optional_matcher); // Init. ivars->opt_matcher_first_time = true; DECREF(children); return self; }
PolyMatcher* PolyMatcher_new(VArray *children, Similarity *sim) { PolyMatcher *self = (PolyMatcher*)VTable_Make_Obj(&POLYMATCHER); return PolyMatcher_init(self, children, sim); }