Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-04-27 21:10:31 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-04-27 21:12:48 +0300
commit278ff15c7f3c4a91ba049b7a13ecf8a4183ebf67 (patch)
treee3de79327764d875dff3960746ec899041c6e808 /source/blender/blenlib/intern/array_utils.c
parent6ada7a1a0b76d7c1d1203800c0bd84c5d1dc0f86 (diff)
BLI_array: add permute utility function
Diffstat (limited to 'source/blender/blenlib/intern/array_utils.c')
-rw-r--r--source/blender/blenlib/intern/array_utils.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/array_utils.c b/source/blender/blenlib/intern/array_utils.c
index 173effbc434..efa107ed703 100644
--- a/source/blender/blenlib/intern/array_utils.c
+++ b/source/blender/blenlib/intern/array_utils.c
@@ -25,6 +25,8 @@
#include <string.h>
#include <stdlib.h>
+#include "MEM_guardedalloc.h"
+
#include "BLI_array_utils.h"
#include "BLI_sys_types.h"
@@ -69,6 +71,36 @@ void _bli_array_wrap(void *arr_v, unsigned int arr_len, size_t arr_stride, int d
}
}
+void _bli_array_permute(
+ void *arr_v, const unsigned int arr_len, const size_t arr_stride,
+ const unsigned int *order, void *arr_temp)
+{
+ const size_t len = arr_len * arr_stride;
+ const unsigned int arr_stride_uint = arr_stride;
+ void *arr_orig;
+ unsigned int i;
+
+ if (arr_temp == NULL) {
+ arr_orig = MEM_mallocN(len, __func__);
+ }
+ else {
+ arr_orig = arr_temp;
+ }
+
+ memcpy(arr_orig, arr_v, len);
+
+ for (i = 0; i < arr_len; i++) {
+ BLI_assert(order[i] < arr_len);
+ memcpy(POINTER_OFFSET(arr_v, arr_stride_uint * i),
+ POINTER_OFFSET(arr_orig, arr_stride_uint * order[i]),
+ arr_stride);
+ }
+
+ if (arr_temp == NULL) {
+ MEM_freeN(arr_orig);
+ }
+}
+
/**
* \note Not efficient, use for error checks/asserts.
*/