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:
authorJacques Lucke <mail@jlucke.com>2019-09-13 11:06:02 +0300
committerJacques Lucke <mail@jlucke.com>2019-09-13 11:06:02 +0300
commit1c44d08a69eb3e66c7f942d748f549d6b8ca138f (patch)
treeb74784ffdc6f6a66a92d02a985865247101a6093 /source/blender/blenlib/intern/math_base_inline.c
parent8d12c2a83658cb6b1311197c292e5906394c4321 (diff)
BLI: new C++ hash table data structures
This commit adds some new hashing based data structures to blenlib. All of them use open addressing with probing currently. Furthermore, they support small object optimization, but it is not customizable yet. I'll add support for this when necessary. The following main data structures are included: **Set** A collection of values, where every value must exist at most once. This is similar to a Python `set`. **SetVector** A combination of a Set and a Vector. It supports fast search for elements and maintains insertion order when there are no deletes. All elements are stored in a continuous array. So they can be iterated over using a normal `ArrayRef`. **Map** A set of key-value-pairs, where every key must exist at most once. This is similar to a Python `dict`. **StringMap** A special map for the case when the keys are strings. This case is fairly common and allows for some optimizations. Most importantly, many unnecessary allocations can be avoided by storing strings in a single buffer. Furthermore, the interface of this class uses `StringRef` to avoid unnecessary conversions. This commit is a continuation of rB369d5e8ad2bb7.
Diffstat (limited to 'source/blender/blenlib/intern/math_base_inline.c')
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index 47327a878d4..0309876d8fb 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -230,6 +230,21 @@ MINLINE unsigned power_of_2_min_u(unsigned x)
return x - (x >> 1);
}
+MINLINE unsigned int log2_floor_u(unsigned int x)
+{
+ return x <= 1 ? 0 : 1 + log2_floor_u(x >> 1);
+}
+
+MINLINE unsigned int log2_ceil_u(unsigned int x)
+{
+ if (is_power_of_2_i((int)x)) {
+ return log2_floor_u(x);
+ }
+ else {
+ return log2_floor_u(x) + 1;
+ }
+}
+
/* rounding and clamping */
#define _round_clamp_fl_impl(arg, ty, min, max) \