diff --git a/README.md b/README.md index 4fc07f6..8a7d37f 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ type Interface interface { #####ArrayList -This structure implements the List interface and is backed by a dynamic array that grows and shrinks implicitly (by 50% when capacity is reached). +This structure implements the List interface and is backed by a dynamic array that grows and shrinks implicitly (by 100% when capacity is reached). Direct access method _Get(index)_ is guaranteed a constant time performance. Remove is of linear time performance. Checking with _Contains()_ is of quadratic complexity. diff --git a/lists/arraylist/arraylist.go b/lists/arraylist/arraylist.go index 3480d5c..c87dac9 100644 --- a/lists/arraylist/arraylist.go +++ b/lists/arraylist/arraylist.go @@ -47,8 +47,8 @@ type List struct { } const ( - GROWTH_FACTOR = float32(1.5) // growth by 50% - SHRINK_FACTOR = float32(0.5) // shrink when size is 50% of capacity (0 means never shrink) + GROWTH_FACTOR = float32(2.0) // growth by 100% + SHRINK_FACTOR = float32(0.25) // shrink when size is 25% of capacity (0 means never shrink) ) // Instantiates a new empty list @@ -165,7 +165,7 @@ func (list *List) resize(cap int) { // Expand the array if necessary, i.e. capacity will be reached if we add n elements func (list *List) growBy(n int) { - // Grow when capacity is reached by a factor of 1.5 and add number of elements + // When capacity is reached, grow by a factor of GROWTH_FACTOR and add number of elements currentCapacity := cap(list.elements) if list.size+n >= currentCapacity { newCapacity := int(GROWTH_FACTOR * float32(currentCapacity+n))