MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / NewCapacity

Method NewCapacity

structure/dynamicarray/dynamicarray.go:96–108  ·  view source on GitHub ↗

NewCapacity function increase the Capacity

()

Source from the content-addressed store, hash-verified

94
95// NewCapacity function increase the Capacity
96func (da *DynamicArray) NewCapacity() {
97 if da.Capacity == 0 {
98 da.Capacity = defaultCapacity
99 } else {
100 da.Capacity = da.Capacity << 1
101 }
102
103 newDataElement := make([]any, da.Capacity)
104
105 copy(newDataElement, da.ElementData)
106
107 da.ElementData = newDataElement
108}

Callers 1

AddMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected