Vuo 2.4.4
Loading...
Searching...
No Matches
VuoSort.c
Go to the documentation of this file.
1
10#include "VuoSort.h"
11
12#include <math.h>
13
14#ifdef VUO_COMPILER
16 "title" : "VuoSort",
17 "dependencies" : [
18 ]
19 });
20#endif
21
26static int compareFloats(const void *a, const void *b)
27{
30
31 return copysign(1, aa->value - bb->value);
32}
33
37void VuoSort_sortArrayByOtherArray(void *array, unsigned long elemCount, unsigned long elemSize, VuoIndexedFloat *other)
38{
39 qsort(other, elemCount, sizeof(VuoIndexedFloat), compareFloats);
40
41 char *srcBytes = (char *)malloc(elemCount * elemSize);
42 memcpy(srcBytes, array, elemCount * elemSize);
43
44 char *dstBytes = (char *)array;
45
46 for (size_t i = 0; i < elemCount; ++i)
47 memcpy(dstBytes + i * elemSize, srcBytes + other[i].index * elemSize, elemSize);
48
49 free(srcBytes);
50}