[Bf-blender-cvs] [b9fee1a5d72] functions: return index when value was inserted before

Jacques Lucke noreply at git.blender.org
Wed Jul 3 19:14:17 CEST 2019


Commit: b9fee1a5d7297b95981e4ec3a7f5dcfee623258f
Author: Jacques Lucke
Date:   Wed Jul 3 17:09:33 2019 +0200
Branches: functions
https://developer.blender.org/rBb9fee1a5d7297b95981e4ec3a7f5dcfee623258f

return index when value was inserted before

===================================================================

M	source/blender/blenlib/BLI_array_lookup.hpp
M	source/blender/blenlib/BLI_small_map.hpp
M	source/blender/blenlib/BLI_small_set.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_array_lookup.hpp b/source/blender/blenlib/BLI_array_lookup.hpp
index 131def71461..618441b9fc5 100644
--- a/source/blender/blenlib/BLI_array_lookup.hpp
+++ b/source/blender/blenlib/BLI_array_lookup.hpp
@@ -91,7 +91,7 @@ class ArrayLookup {
     }
   }
 
-  bool add(Item *array, const Key &key, uint potential_index)
+  uint add(Item *array, const Key &key, uint desired_new_index)
   {
     int dummy_slot = -1;
     ITER_SLOTS (key, slot, state) {
@@ -99,18 +99,18 @@ class ArrayLookup {
         if (dummy_slot == -1) {
           bool map_changed = this->ensure_can_add(array);
           if (map_changed) {
-            this->insert_index_for_key(key, potential_index);
+            this->insert_index_for_key(key, desired_new_index);
           }
           else {
-            m_map[slot] = potential_index;
+            m_map[slot] = desired_new_index;
           }
         }
         else {
-          m_map[slot] = potential_index;
+          m_map[slot] = desired_new_index;
           m_dummy_amount--;
         }
         m_length++;
-        return true;
+        return desired_new_index;
       }
       else if (state == SLOT_DUMMY) {
         if (dummy_slot == -1) {
@@ -118,7 +118,7 @@ class ArrayLookup {
         }
       }
       else if (GetKey(array[state]) == key) {
-        return false;
+        return state;
       }
     }
   }
diff --git a/source/blender/blenlib/BLI_small_map.hpp b/source/blender/blenlib/BLI_small_map.hpp
index f986c66ede6..e8add508606 100644
--- a/source/blender/blenlib/BLI_small_map.hpp
+++ b/source/blender/blenlib/BLI_small_map.hpp
@@ -59,8 +59,9 @@ template<typename K, typename V, uint N = 4> class SmallMap {
    */
   bool add(const K &key, const V &value)
   {
-    uint potential_index = m_entries.size();
-    bool newly_inserted = m_lookup.add(m_entries.begin(), key, potential_index);
+    uint desired_new_index = m_entries.size();
+    uint value_index = m_lookup.add(m_entries.begin(), key, desired_new_index);
+    bool newly_inserted = value_index == desired_new_index;
     if (newly_inserted) {
       m_entries.append({key, value});
     }
diff --git a/source/blender/blenlib/BLI_small_set.hpp b/source/blender/blenlib/BLI_small_set.hpp
index 273853a83f4..9d378bdc2f5 100644
--- a/source/blender/blenlib/BLI_small_set.hpp
+++ b/source/blender/blenlib/BLI_small_set.hpp
@@ -95,8 +95,9 @@ template<typename T, uint N = 4> class SmallSet {
    */
   bool add(const T &value)
   {
-    uint potential_index = m_elements.size();
-    bool newly_inserted = m_lookup.add(m_elements.begin(), value, potential_index);
+    uint desired_new_index = m_elements.size();
+    uint value_index = m_lookup.add(m_elements.begin(), value, desired_new_index);
+    bool newly_inserted = value_index == desired_new_index;
     if (newly_inserted) {
       m_elements.append(value);
     }



More information about the Bf-blender-cvs mailing list