Browse Source

table: reserve/capacity/shrink_to_fit

Michele Caini 1 year ago
parent
commit
f180927380
1 changed files with 26 additions and 0 deletions
  1. 26 0
      src/entt/entity/table.hpp

+ 26 - 0
src/entt/entity/table.hpp

@@ -111,6 +111,32 @@ public:
         return std::get<0>(payload).get_allocator();
     }
 
+    /**
+     * @brief Increases the capacity of a table.
+     *
+     * If the new capacity is greater than the current capacity, new storage is
+     * allocated, otherwise the method does nothing.
+     *
+     * @param cap Desired capacity.
+     */
+    void reserve(const size_type cap) override {
+        (std::get<container_for<Row>>(payload).reserve(cap), ...);
+    }
+
+    /**
+     * @brief Returns the number of rows that a table has currently allocated
+     * space for.
+     * @return Capacity of the table.
+     */
+    [[nodiscard]] size_type capacity() const noexcept override {
+        return std::get<0>(payload).capacity();
+    }
+
+    /*! @brief Requests the removal of unused capacity. */
+    void shrink_to_fit() override {
+        (std::get<container_for<Row>>(payload).shrink_to_fit(), ...);
+    }
+
 private:
     container_type payload;
 };