Vuo
2.1.1
library
VuoSort.c
Go to the documentation of this file.
1
10
#include "
VuoSort.h
"
11
12
#include "
module.h
"
13
14
#ifdef VUO_COMPILER
15
VuoModuleMetadata
({
16
"title"
:
"VuoSort"
,
17
"dependencies"
: [
18
]
19
});
20
#endif
21
26
static
int
compareFloats
(
const
void
*a,
const
void
*b)
27
{
28
VuoIndexedFloat
*aa = (
VuoIndexedFloat
*)a;
29
VuoIndexedFloat
*bb = (
VuoIndexedFloat
*)b;
30
31
return
copysign(1, aa->
value
- bb->
value
);
32
}
33
37
void
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
}
Generated on Thu Jul 9 2020 21:02:22 for Vuo by
1.8.18