[Bf-blender-cvs] [a00101ae5d7] functions: move hash table slot iterators out of class

Jacques Lucke noreply at git.blender.org
Mon Aug 19 18:41:53 CEST 2019


Commit: a00101ae5d7b34f7aabd1b2d1439bd3224bd8a5c
Author: Jacques Lucke
Date:   Mon Aug 19 18:24:16 2019 +0200
Branches: functions
https://developer.blender.org/rBa00101ae5d7b34f7aabd1b2d1439bd3224bd8a5c

move hash table slot iterators out of class

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

M	source/blender/blenlib/BLI_map.hpp
M	source/blender/blenlib/BLI_set.hpp
M	source/blender/blenlib/BLI_set_vector.hpp

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

diff --git a/source/blender/blenlib/BLI_map.hpp b/source/blender/blenlib/BLI_map.hpp
index 0a2024d5d0c..093250bc6b8 100644
--- a/source/blender/blenlib/BLI_map.hpp
+++ b/source/blender/blenlib/BLI_map.hpp
@@ -30,6 +30,27 @@
 
 namespace BLI {
 
+// clang-format off
+
+#define ITER_SLOTS_BEGIN(KEY, ARRAY, OPTIONAL_CONST, R_ITEM, R_OFFSET) \
+  uint32_t hash = MyHash<KeyT>{}(KEY); \
+  uint32_t perturb = hash; \
+  while (true) { \
+    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
+    uint8_t R_OFFSET = hash & OFFSET_MASK; \
+    uint8_t initial_offset = R_OFFSET; \
+    OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
+    do {
+
+#define ITER_SLOTS_END(R_OFFSET) \
+      R_OFFSET = (R_OFFSET + 1) & OFFSET_MASK; \
+    } while (R_OFFSET != initial_offset); \
+    perturb >>= 5; \
+    hash = hash * 5 + 1 + perturb; \
+  } ((void)0)
+
+// clang-format on
+
 template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator> class Map {
  private:
   static constexpr uint32_t OFFSET_MASK = 3;
@@ -149,27 +170,6 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
  public:
   Map() = default;
 
-  // clang-format off
-
-#define ITER_SLOTS_BEGIN(KEY, ARRAY, OPTIONAL_CONST, R_ITEM, R_OFFSET) \
-  uint32_t hash = MyHash<KeyT>{}(KEY); \
-  uint32_t perturb = hash; \
-  while (true) { \
-    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
-    uint8_t R_OFFSET = hash & OFFSET_MASK; \
-    uint8_t initial_offset = R_OFFSET; \
-    OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
-    do {
-
-#define ITER_SLOTS_END(R_OFFSET) \
-      R_OFFSET = (R_OFFSET + 1) & OFFSET_MASK; \
-    } while (R_OFFSET != initial_offset); \
-    perturb >>= 5; \
-    hash = hash * 5 + 1 + perturb; \
-  } ((void)0)
-
-  // clang-format on
-
   void add_new(const KeyT &key, const ValueT &value)
   {
     BLI_assert(!this->contains(key));
@@ -519,9 +519,9 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
     }
     ITER_SLOTS_END(offset);
   }
+};
 
 #undef ITER_SLOTS_BEGIN
 #undef ITER_SLOTS_END
-};
 
 };  // namespace BLI
diff --git a/source/blender/blenlib/BLI_set.hpp b/source/blender/blenlib/BLI_set.hpp
index 1c66ca7616b..d75e170bbb8 100644
--- a/source/blender/blenlib/BLI_set.hpp
+++ b/source/blender/blenlib/BLI_set.hpp
@@ -6,6 +6,27 @@
 
 namespace BLI {
 
+// clang-format off
+
+#define ITER_SLOTS_BEGIN(VALUE, ARRAY, OPTIONAL_CONST, R_ITEM, R_OFFSET) \
+  uint32_t hash = MyHash<T>{}(VALUE); \
+  uint32_t perturb = hash; \
+  while (true) { \
+    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
+    uint8_t R_OFFSET = hash & OFFSET_MASK; \
+    uint8_t initial_offset = R_OFFSET; \
+    OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
+    do {
+
+#define ITER_SLOTS_END(R_OFFSET) \
+      R_OFFSET = (R_OFFSET + 1) & OFFSET_MASK; \
+    } while (R_OFFSET != initial_offset); \
+    perturb >>= 5; \
+    hash = hash * 5 + 1 + perturb; \
+  } ((void)0)
+
+// clang-format on
+
 template<typename T, typename Allocator = GuardedAllocator> class Set {
  private:
   static constexpr uint32_t OFFSET_MASK = 3;
@@ -128,27 +149,6 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
   {
   }
 
-  // clang-format off
-
-#define ITER_SLOTS_BEGIN(VALUE, ARRAY, OPTIONAL_CONST, R_ITEM, R_OFFSET) \
-  uint32_t hash = MyHash<T>{}(VALUE); \
-  uint32_t perturb = hash; \
-  while (true) { \
-    uint32_t item_index = (hash & ARRAY.slot_mask()) >> 2; \
-    uint8_t R_OFFSET = hash & OFFSET_MASK; \
-    uint8_t initial_offset = R_OFFSET; \
-    OPTIONAL_CONST Item &R_ITEM = ARRAY.item(item_index); \
-    do {
-
-#define ITER_SLOTS_END(R_OFFSET) \
-      R_OFFSET = (R_OFFSET + 1) & OFFSET_MASK; \
-    } while (R_OFFSET != initial_offset); \
-    perturb >>= 5; \
-    hash = hash * 5 + 1 + perturb; \
-  } ((void)0)
-
-  // clang-format on
-
   void reserve(uint32_t min_usable_slots)
   {
     this->grow(min_usable_slots);
@@ -398,9 +398,9 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
     }
     ITER_SLOTS_END(offset);
   }
+};
 
 #undef ITER_SLOTS_BEGIN
 #undef ITER_SLOTS_END
-};
 
 }  // namespace BLI
diff --git a/source/blender/blenlib/BLI_set_vector.hpp b/source/blender/blenlib/BLI_set_vector.hpp
index ee043130be1..7206140b3a2 100644
--- a/source/blender/blenlib/BLI_set_vector.hpp
+++ b/source/blender/blenlib/BLI_set_vector.hpp
@@ -26,6 +26,24 @@
 
 namespace BLI {
 
+// clang-format off
+
+#define ITER_SLOTS_BEGIN(VALUE, ARRAY, OPTIONAL_CONST, R_SLOT) \
+  uint32_t hash = MyHash<T>{}(VALUE); \
+  uint32_t perturb = hash; \
+  while (true) { \
+    for (uint i = 0; i < 4; i++) {\
+      uint32_t slot_index = (hash + i) & ARRAY.slot_mask(); \
+      OPTIONAL_CONST Slot &R_SLOT = ARRAY.item(slot_index);
+
+#define ITER_SLOTS_END \
+    } \
+    perturb >>= 5; \
+    hash = hash * 5 + 1 + perturb; \
+  } ((void)0)
+
+// clang-format on
+
 template<typename T, typename Allocator = GuardedAllocator> class SetVector {
  private:
   static constexpr int32_t IS_EMPTY = -1;
@@ -104,24 +122,6 @@ template<typename T, typename Allocator = GuardedAllocator> class SetVector {
     this->add_multiple(values);
   }
 
-  // clang-format off
-
-#define ITER_SLOTS_BEGIN(VALUE, ARRAY, OPTIONAL_CONST, R_SLOT) \
-  uint32_t hash = MyHash<T>{}(VALUE); \
-  uint32_t perturb = hash; \
-  while (true) { \
-    for (uint i = 0; i < 4; i++) {\
-      uint32_t slot_index = (hash + i) & ARRAY.slot_mask(); \
-      OPTIONAL_CONST Slot &R_SLOT = ARRAY.item(slot_index);
-
-#define ITER_SLOTS_END \
-    } \
-    perturb >>= 5; \
-    hash = hash * 5 + 1 + perturb; \
-  } ((void)0)
-
-  // clang-format on
-
   void add_new(const T &value)
   {
     BLI_assert(!this->contains(value));
@@ -295,9 +295,9 @@ template<typename T, typename Allocator = GuardedAllocator> class SetVector {
     }
     ITER_SLOTS_END;
   }
+};
 
 #undef ITER_SLOTS_BEGIN
 #undef ITER_SLOTS_END
-};
 
 }  // namespace BLI



More information about the Bf-blender-cvs mailing list