BBSortEx* BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) { SortEx_init((SortExternal*)self, sizeof(Obj*)); self->external_tick = 0; self->external = (VArray*)INCREF(external); self->mem_consumed = 0; BBSortEx_Set_Mem_Thresh(self, mem_threshold); return self; }
BBSortEx* BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) { SortEx_init((SortExternal*)self); BBSortExIVARS *const ivars = BBSortEx_IVARS(self); ivars->external_tick = 0; ivars->external = (VArray*)INCREF(external); ivars->mem_consumed = 0; BBSortEx_Set_Mem_Thresh(self, mem_threshold); return self; }
void BBSortEx_flip(BBSortEx *self) { uint32_t run_mem_thresh = 65536; BBSortEx_Flush(self); // Recalculate the approximate mem allowed for each run. uint32_t num_runs = VA_Get_Size(self->runs); if (num_runs) { run_mem_thresh = (self->mem_thresh / 2) / num_runs; if (run_mem_thresh < 65536) { run_mem_thresh = 65536; } } for (uint32_t i = 0; i < num_runs; i++) { BBSortEx *run = (BBSortEx*)VA_Fetch(self->runs, i); BBSortEx_Set_Mem_Thresh(run, run_mem_thresh); } // OK to fetch now. self->flipped = true; }