diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2018-03-18 00:40:38 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2018-03-18 00:40:38 +0100 |
| commit | ff5f5c50bd2ce931a62b2eb1b0aed97c0fa370c5 (patch) | |
| tree | a38bfa6769aa8165b417babd4053834904ce5a89 /DTQuickSort.c | |
| parent | 9b5d0a3ddf41e686439dcda1edfe11eee51c3b07 (diff) | |
| download | System.c4g-ff5f5c50bd2ce931a62b2eb1b0aed97c0fa370c5.tar.gz System.c4g-ff5f5c50bd2ce931a62b2eb1b0aed97c0fa370c5.zip | |
Update to newest version
DTCallback: Add fast callbacks (only Object/DefinitionCallback() is possible) and restructure CallA() for hopefully better performance
DTCallback: Fix all custom calls to allow overriding in Definition- and Object-context
DTFilterObjects: new addition
DTMenuCompatibility: add Menu_Entry compatibility version due to the new Menu_Entry-API
DTObjectSerializing: small progress, still WIP
DTPlayers: Fix constant enum definitions (thanks to the preprocessor's precalculator)
DTQuickSort: Add custom callback args
DTScopedVars: Fix all custom calls to allow overriding in Definition- and Object-context
DTScopedVars: CustomScopedVar-implementations must now return another less custom ScopedVar instead of a reference (due to _inherited())
DTTransform: disable MirrorZ
DTTransform: fix Matrix3x3Multiply and thus PreTransform
DTTransform: fix whitespace
DTTransform: update comments
DTUTility: Fix indentation and whitespace
DTUtility: Add GetShape, InRect and GetPlayerByID
DTCallback, DTObjectSerializing: Rely on the preprocessor's precalculator
Diffstat (limited to 'DTQuickSort.c')
| -rw-r--r-- | DTQuickSort.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/DTQuickSort.c b/DTQuickSort.c index 7434263..8f480ca 100644 --- a/DTQuickSort.c +++ b/DTQuickSort.c @@ -17,17 +17,17 @@ global func SortNumericInverse(int a, int b) return -SortNumeric(a, b); } -global func QSort(array& data, callback) // WARNING: Can cause stack-overflow with too much data +global func QSort(array& data, callback, callbackArgs) // WARNING: Can cause stack-overflow with too much data { if(callback == true) { callback = GlobalCallback("SortNumericInverse"); } - QSort_Part(data, callback || GlobalCallback("SortNumeric"), 0, GetLength(data) - 1); + QSort_Part(data, callback || GlobalCallback("SortNumeric"), 0, GetLength(data) - 1, callbackArgs); return data; } -global func QSort_Part(array& data, callback, int left, int right) +global func QSort_Part(array& data, callback, int left, int right, callbackArgs) { if(left < right) { @@ -35,16 +35,16 @@ global func QSort_Part(array& data, callback, int left, int right) var pPos = RandomX(left, right); var p = data[pPos]; var tmp; - + tmp = data[pPos]; data[pPos] = data[right]; data[right] = tmp; pPos = right; - + var i = left - 1; for(var j = left; j <= right; ++j) { - if(Call(callback, data[j], p) < 0) + if(Call(callback, data[j], p, callbackArgs) < 0) { ++i; tmp = data[i]; @@ -52,15 +52,15 @@ global func QSort_Part(array& data, callback, int left, int right) data[j] = tmp; } } - + ++i; - + tmp = data[i]; data[i] = data[pPos]; data[pPos] = tmp; // ----- - - QSort_Part(data, callback, left, i - 1); - QSort_Part(data, callback, i + 1, right); + + QSort_Part(data, callback, left, i - 1, callbackArgs); + QSort_Part(data, callback, i + 1, right, callbackArgs); } } |
