void PolyLex_Seek_IMP(PolyLexicon *self, Obj *target) { PolyLexiconIVARS *const ivars = PolyLex_IVARS(self); Vector *seg_lexicons = ivars->seg_lexicons; SegLexQueue *lex_q = ivars->lex_q; if (target == NULL) { PolyLex_Reset(self); return; } // Refresh the queue, set vars. S_refresh_lex_q(lex_q, seg_lexicons, target); SegLexicon *least = (SegLexicon*)SegLexQ_Peek(lex_q); DECREF(ivars->term); ivars->term = NULL; if (least) { Obj *least_term = SegLex_Get_Term(least); ivars->term = least_term ? Obj_Clone(least_term) : NULL; } // Scan up to the real target. do { if (ivars->term) { const int32_t comparison = Obj_Compare_To(ivars->term, target); if (comparison >= 0) { break; } } } while (PolyLex_Next(self)); }
bool PolyLex_Next_IMP(PolyLexicon *self) { PolyLexiconIVARS *const ivars = PolyLex_IVARS(self); SegLexQueue *lex_q = ivars->lex_q; SegLexicon *top_seg_lexicon = (SegLexicon*)SegLexQ_Peek(lex_q); // Churn through queue items with equal terms. while (top_seg_lexicon != NULL) { Obj *const candidate = SegLex_Get_Term(top_seg_lexicon); if ((candidate && !ivars->term) || Obj_Compare_To(ivars->term, candidate) != 0 ) { // Succeed if the next item in the queue has a different term. DECREF(ivars->term); ivars->term = Obj_Clone(candidate); return true; } else { SegLexicon *seg_lex = (SegLexicon*)SegLexQ_Pop(lex_q); DECREF(seg_lex); if (SegLex_Next(top_seg_lexicon)) { SegLexQ_Insert(lex_q, INCREF(top_seg_lexicon)); } top_seg_lexicon = (SegLexicon*)SegLexQ_Peek(lex_q); } } // If queue is empty, iterator is finished. DECREF(ivars->term); ivars->term = NULL; return false; }
static int S_default_compare(void *context, const void *va, const void *vb) { Obj *a = *(Obj**)va; Obj *b = *(Obj**)vb; UNUSED_VAR(context); if (a != NULL && b != NULL) { return Obj_Compare_To(a, b); } else if (a == NULL && b == NULL) { return 0; } else if (a == NULL) { return 1; } // NULL to the back else /* b == NULL */ { return -1; } // NULL to the back }
int32_t IntNum_compare_to(IntNum *self, Obj *other) { if (!Obj_Is_A(other, INTNUM)) { return -Obj_Compare_To(other, (Obj*)self); } int64_t self_value = IntNum_To_I64(self); int64_t other_value = Obj_To_I64(other); if (self_value < other_value) { return -1; } else if (self_value > other_value) { return 1; } return 0; }
static void S_attempt_Compare_To(void *context) { Obj_Compare_To((Obj*)context, (Obj*)context); }
int BlobSortEx_Compare_IMP(BlobSortEx *self, Obj **ptr_a, Obj **ptr_b) { UNUSED_VAR(self); return Obj_Compare_To(*ptr_a, *ptr_b); }
int32_t FType_Compare_Values_IMP(FieldType *self, Obj *a, Obj *b) { UNUSED_VAR(self); return Obj_Compare_To(a, b); }