[Bf-blender-cvs] [bc62878f985] soc-2021-adaptive-cloth: bli: generational_arena: constructors and reserve()

ishbosamiya noreply at git.blender.org
Fri Jun 18 11:22:43 CEST 2021


Commit: bc62878f985cbbc677341207516dcb7e73d05e86
Author: ishbosamiya
Date:   Tue Jun 15 12:48:10 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rBbc62878f985cbbc677341207516dcb7e73d05e86

bli: generational_arena: constructors and reserve()

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

M	source/blender/blenlib/BLI_generational_arena.hh

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

diff --git a/source/blender/blenlib/BLI_generational_arena.hh b/source/blender/blenlib/BLI_generational_arena.hh
index 7719ce9aa85..65851467c5b 100644
--- a/source/blender/blenlib/BLI_generational_arena.hh
+++ b/source/blender/blenlib/BLI_generational_arena.hh
@@ -91,15 +91,39 @@ class Arena {
   /* non-static data members */
   struct EntryNoExist {
     std::optional<usize> next_free;
+
+    EntryNoExist()
+    {
+    }
+
+    EntryNoExist(usize next_free)
+    {
+      this->next_free = next_free;
+    }
+
+    EntryNoExist(std::optional<usize> next_free)
+    {
+      this->next_free = next_free;
+    }
   };
   struct EntryExist {
     T value;
     usize generation;
   };
 
+  blender::Vector<Entry> data;
+  std::optional<usize> next_free_head;
+  usize generation;
+  usize length;
+
  public:
   /* default constructor */
+  Arena() = default;
   /* other constructors */
+  Arena(const usize size) : Arena()
+  {
+    this->reserve(size);
+  }
   /* copy constructor */
   /* move constructor */
 
@@ -111,6 +135,28 @@ class Arena {
 
   /* all public static methods */
   /* all public non-static methods */
+  void reserve(const usize new_cap)
+  {
+    /* Must only increase capacity */
+    if (new_cap < this->data.size()) {
+      return;
+    }
+
+    this->data.reserve(new_cap);
+    /* next_free_head is set to start of extended list
+     *
+     * in the extended elements, next_free is set to the next element
+     *
+     * last element in the extended elements's next_free is the old
+     * next_free_head */
+    auto const old_next_free_head = this->next_free_head;
+    auto const start = this->data.size();
+    for (auto i = start; i < new_cap - 1; i++) {
+      this->data.append(EntryNoExist(i + 1));
+    }
+    this->data.append(EntryNoExist(old_next_free_head));
+    this->next_free_head = start;
+  }
 
  protected:
   /* all protected static methods */



More information about the Bf-blender-cvs mailing list