/**************************************************************************** ** ** This file is part of GAP, a system for computational discrete algebra. ** ** Copyright of GAP belongs to its developers, whose names are too numerous ** to list here. Please refer to the COPYRIGHT file for details. ** ** SPDX-License-Identifier: GPL-2.0-or-later ** ** WARNING: This file should NOT be directly included. It is designed ** to instantiate a generic dynamic array type based on #defines that ** have to be set before including the file, and the file can be included ** repeatedly with different parameters.
*/
// Parameters: // // #define ELEM_TYPE type of elements // #define COMPARE comparison function for elements (optional) // #define ALLOC allocation function (optional) // #define DEALLOC deallocation function (optional)
#ifdef COMPARE staticinlinevoid FN(Sort)(Array * arr)
{ Int len = arr->len; if (len <= 1) return;
ELEM_TYPE * in = ALLOC(ELEM_TYPE, len);
ELEM_TYPE * out = ALLOC(ELEM_TYPE, len);
memcpy(in, arr->items, sizeof(ELEM_TYPE) * len); Int step = 1; while (step < len) { for (Int i = 0; i < len; i += step * 2) { Int p = i, l = i, r = i + step, lmax = l + step, rmax = r + step; if (rmax > len)
rmax = len; if (lmax > len)
lmax = len; while (l < lmax && r < rmax) { int c = COMPARE(in[l], in[r]); if (c < 0) {
out[p++] = in[l++];
} else {
out[p++] = in[r++];
}
} while (l < lmax) {
out[p++] = in[l++];
} while (r < rmax) {
out[p++] = in[r++];
}
}
ELEM_TYPE * tmp = in;
in = out;
out = tmp;
step += step;
}
DEALLOC(arr->items);
DEALLOC(out);
arr->items = in;
arr->cap = len; // we allocated only len items for 'in'.
} #endif
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.