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>2016-06-08 11:34:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-06-08 12:12:23 +0300
commit0a029e3dd19653ff11cee1d257762347e69600fb (patch)
tree12865a3d4390f52c6496d9b230b84a2daa07b205 /source/blender/blenlib
parente623d6b223f4fb6f9ff03aef3e81c4b433692c7b (diff)
BLI_array_store: move helper functions into their own API
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_array_store_utils.h50
-rw-r--r--source/blender/blenlib/CMakeLists.txt2
-rw-r--r--source/blender/blenlib/intern/array_store_utils.c103
3 files changed, 155 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_array_store_utils.h b/source/blender/blenlib/BLI_array_store_utils.h
new file mode 100644
index 00000000000..6b2a28846f4
--- /dev/null
+++ b/source/blender/blenlib/BLI_array_store_utils.h
@@ -0,0 +1,50 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_ARRAY_STORE_UTILS_H__
+#define __BLI_ARRAY_STORE_UTILS_H__
+
+/** \file BLI_array_store_utils.h
+ * \ingroup bli
+ */
+
+struct BArrayStore;
+
+struct BArrayStore_AtSize {
+ struct BArrayStore **stride_table;
+ int stride_table_len;
+};
+
+BArrayStore *BLI_array_store_at_size_ensure(
+ struct BArrayStore_AtSize *bs_stride,
+ const int stride, const int chunk_size);
+
+BArrayStore *BLI_array_store_at_size_get(
+ struct BArrayStore_AtSize *bs_stride,
+ const int stride);
+
+void BLI_array_store_at_size_clear(
+ struct BArrayStore_AtSize *bs_stride);
+
+void BLI_array_store_at_size_calc_memory_usage(
+ struct BArrayStore_AtSize *bs_stride,
+ size_t *r_size_expanded, size_t *r_size_compacted);
+
+#endif /* __BLI_ARRAY_STORE_UTILS_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 42d958774d8..9978d1d19af 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SRC
intern/BLI_mempool.c
intern/DLRB_tree.c
intern/array_store.c
+ intern/array_store_utils.c
intern/array_utils.c
intern/astar.c
intern/boxpack2d.c
@@ -122,6 +123,7 @@ set(SRC
BLI_args.h
BLI_array.h
BLI_array_store.h
+ BLI_array_store_utils.h
BLI_array_utils.h
BLI_astar.h
BLI_bitmap.h
diff --git a/source/blender/blenlib/intern/array_store_utils.c b/source/blender/blenlib/intern/array_store_utils.c
new file mode 100644
index 00000000000..83cd28ddf11
--- /dev/null
+++ b/source/blender/blenlib/intern/array_store_utils.c
@@ -0,0 +1,103 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenlib/intern/array_store_utils.c
+ * \ingroup bli
+ * \brief Helper functions for BLI_array_store API.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "BLI_array_store.h"
+#include "BLI_array_store_utils.h" /* own include */
+
+#include "BLI_math_base.h"
+
+BArrayStore *BLI_array_store_at_size_ensure(
+ struct BArrayStore_AtSize *bs_stride,
+ const int stride, const int chunk_size)
+{
+ if (bs_stride->stride_table_len < stride) {
+ bs_stride->stride_table_len = stride;
+ bs_stride->stride_table = MEM_recallocN(bs_stride->stride_table, sizeof(*bs_stride->stride_table) * stride);
+ }
+ BArrayStore **bs_p = &bs_stride->stride_table[stride - 1];
+
+ if ((*bs_p) == NULL) {
+#if 0
+ unsigned int chunk_count = chunk_size;
+#else
+ /* calculate best chunk-count to fit a power of two */
+ unsigned int chunk_count = chunk_size;
+ {
+ unsigned int size = chunk_count * stride;
+ size = power_of_2_max_u(size);
+ size = MEM_SIZE_OPTIMAL(size);
+ chunk_count = size / stride;
+ }
+#endif
+
+ (*bs_p) = BLI_array_store_create(stride, chunk_count);
+ }
+ return *bs_p;
+}
+
+BArrayStore *BLI_array_store_at_size_get(
+ struct BArrayStore_AtSize *bs_stride,
+ const int stride)
+{
+ BLI_assert(stride > 0 && stride <= bs_stride->stride_table_len);
+ return bs_stride->stride_table[stride - 1];
+}
+
+void BLI_array_store_at_size_clear(
+ struct BArrayStore_AtSize *bs_stride)
+{
+ for (int i = 0; i < bs_stride->stride_table_len; i += 1) {
+ if (bs_stride->stride_table[i]) {
+ BLI_array_store_destroy(bs_stride->stride_table[i]);
+ }
+ }
+
+ MEM_freeN(bs_stride->stride_table);
+ bs_stride->stride_table = NULL;
+ bs_stride->stride_table_len = 0;
+}
+
+
+void BLI_array_store_at_size_calc_memory_usage(
+ struct BArrayStore_AtSize *bs_stride,
+ size_t *r_size_expanded, size_t *r_size_compacted)
+{
+ size_t size_compacted = 0;
+ size_t size_expanded = 0;
+ for (int i = 0; i < bs_stride->stride_table_len; i++) {
+ BArrayStore *bs = bs_stride->stride_table[i];
+ if (bs) {
+ size_compacted += BLI_array_store_calc_size_compacted_get(bs);
+ size_expanded += BLI_array_store_calc_size_expanded_get(bs);
+ }
+ }
+
+ *r_size_expanded = size_expanded;
+ *r_size_compacted = size_compacted;
+}