static void sort_rec (intnat * a1, intnat * b1, int i1, int l1, intnat * a2, intnat * b2, int i2, int l2) { int len = l1 - i1; assert (len == l2 - i2); if (len <= cuttoff) isort (a1, b1, i1, l1, a2, b2, i2, l2); else { int len1 = len / 2; int len2 = len - len1; sort_rec (a1, b1, i1 + len1, l1, a2, b2, i2 + len1, l2); sort_rec (a1, b1, i1, i1 + len1, a1, b1, i1 + len2, l1); merge (a1, b1, i1 + len2, l1, a2, b2, i2 + len1, l2, a2, b2, i2, l2); } }
static int *sort_rec (tree23_t *T, int *st, int depth) { if (--depth >= 0) { st = sort_rec (T->left, st, depth); *st++ = T->x1; if (T->x2 > T->x1) { st = sort_rec (T->middle, st, depth); *st++ = T->x2; } st = sort_rec (T->right, st, depth); } else { *st++ = T->x1; if (T->x2 > T->x1) { *st++ = T->x2; } } return st; }
CAMLprim value sort_bigarrays (value va, value vb, value l) { struct caml_ba_array * a0 = Caml_ba_array_val(va); struct caml_ba_array * b0 = Caml_ba_array_val(vb); int len = Long_val (l); assert (a0->dim[0] >= len); assert (b0->dim[0] >= len); intnat * a1 = (intnat *) a0->data; intnat * b1 = (intnat *) b0->data; if (len <= cuttoff) isort (a1, b1, 0, len, a1, b1, 0, len); else { int len1 = len / 2; int len2 = len - len1; intnat * a2 = (intnat *) malloc (len2 * sizeof (intnat)); intnat * b2 = (intnat *) malloc (len2 * sizeof (intnat)); sort_rec (a1, b1, len1, len, a2, b2, 0, len2); sort_rec (a1, b1, 0, len1, a1, b1, len2, len); merge (a1, b1, len2, len, a2, b2, 0, len2, a1, b1, 0, len); free (a2); free (b2); } return Val_unit; }
void Clean_model::sort_rec(File* node, int column, Qt::SortOrder order) { File::Field field; switch (column) { case Clean_model::NAME: field = File::Field::NAME; break; case Clean_model::SIZE: field = File::Field::SIZE; break; case Clean_model::REASON: field = File::Field::DELETE_REASON; break; } node->sort_marked_for_delete(field, from_qt(order)); to_delete_each_rec(node, [column, order] (const File* child) { sort_rec(const_cast<File*>(child), column, order); }); }
static int *sort (tree23_root_t *R, int *st) { if (!R->root) { return st; } return sort_rec (R->root, st, R->depth); }
void Clean_model::sort(int column, Qt::SortOrder order) { sort_rec(&pseudo_root_, column, order); }