Julia does not currently have a well developed interface for changing the size of collections. Resizing provides common methods for growing and shrinking collections. Although the relative position where a resizing method is executed may vary by method and collection type, a common pattern makes them straightforward to use and overload for new collections. For example, the following methods are responsible for growing a collection from the last index:
- Resizing.unsafe_grow_end!(collection, n): assumes that all necessary conditions for growing- collectionby- nelements from the last index are met without checking.
- Resizing.grow_end!(collection, n): Calls- Resizing.unsafe_grow_end!(collection, n)if it can determine that- collectioncan safely grow by- nelements from the last index, returning- trueif successful.
- Resizing.assert_grow_end!(collection, n): Calls- Resizing.grow_end!(collection, n). If- falseis returned it throws an error, otherwise returns- nothing.
Note that grow_end! and unsafe_grow_end! must be defined for each new collection type, but assert_grow_end! can rely completely on the former two methods.
This same pattern exists for shrinking or growing at the beginning, end, or a specified index.