Example #1
0
void
SortEx_Sort_Buffer_IMP(SortExternal *self) {
    SortExternalIVARS *const ivars = SortEx_IVARS(self);
    if (ivars->buf_tick != 0) {
        THROW(ERR, "Cant Sort_Buffer() after fetching %u32 items", ivars->buf_tick);
    }
    if (ivars->buf_max != 0) {
        Class *klass = SortEx_get_class(self);
        CFISH_Sort_Compare_t compare
            = (CFISH_Sort_Compare_t)METHOD_PTR(klass, LUCY_SortEx_Compare);
        if (ivars->scratch_cap < ivars->buf_cap) {
            ivars->scratch_cap = ivars->buf_cap;
            ivars->scratch
                = (Obj**)REALLOCATE(ivars->scratch,
                                    ivars->scratch_cap * sizeof(Obj*));
        }
        Sort_mergesort(ivars->buffer, ivars->scratch, ivars->buf_max,
                       sizeof(Obj*), compare, self);
    }
}
Example #2
0
void
SortEx_Sort_Cache_IMP(SortExternal *self) {
    SortExternalIVARS *const ivars = SortEx_IVARS(self);
    if (ivars->cache_tick != 0) {
        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", ivars->cache_tick);
    }
    if (ivars->cache_max != 0) {
        VTable *vtable = SortEx_Get_VTable(self);
        CFISH_Sort_Compare_t compare
            = (CFISH_Sort_Compare_t)METHOD_PTR(vtable, LUCY_SortEx_Compare);
        if (ivars->scratch_cap < ivars->cache_cap) {
            ivars->scratch_cap = ivars->cache_cap;
            ivars->scratch
                = (uint8_t*)REALLOCATE(ivars->scratch,
                                       ivars->scratch_cap * ivars->width);
        }
        Sort_mergesort(ivars->cache, ivars->scratch, ivars->cache_max,
                       ivars->width, compare, self);
    }
}