[Bf-blender-cvs] [8d55ff177dd] functions: extend set and vector data structure
Jacques Lucke
noreply at git.blender.org
Sun Feb 10 20:25:59 CET 2019
Commit: 8d55ff177dde5cd30b327e5b861bb24b8023cce0
Author: Jacques Lucke
Date: Mon Feb 4 16:40:23 2019 +0100
Branches: functions
https://developer.blender.org/rB8d55ff177dde5cd30b327e5b861bb24b8023cce0
extend set and vector data structure
===================================================================
M source/blender/blenlib/BLI_small_set.hpp
M source/blender/blenlib/BLI_small_vector.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_small_set.hpp b/source/blender/blenlib/BLI_small_set.hpp
index 0eac0b2174c..b385b56db7f 100644
--- a/source/blender/blenlib/BLI_small_set.hpp
+++ b/source/blender/blenlib/BLI_small_set.hpp
@@ -12,6 +12,13 @@ namespace BLI {
public:
SmallSet() = default;
+ SmallSet(const SmallVector<T> values)
+ {
+ for (T value : values) {
+ this->add(value);
+ }
+ }
+
void add(T value)
{
if (!this->contains(value)) {
@@ -34,6 +41,12 @@ namespace BLI {
return this->m_entries.size();
}
+ T any() const
+ {
+ BLI_assert(this->size() > 0);
+ return this->m_entries[0];
+ }
+
/* Iterators */
diff --git a/source/blender/blenlib/BLI_small_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
index 07b002789c7..349fdf8a4f0 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -105,6 +105,16 @@ namespace BLI {
return this->m_size;
}
+ int index(const T &value) const
+ {
+ for (uint i = 0; i < this->m_size; i++) {
+ if (this->m_elements[i] == value) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
T &operator[](const int index)
{
BLI_assert(index >= 0 && index < this->size());
More information about the Bf-blender-cvs
mailing list