[Chapel Merge] Add an initialCapacity keyword argument to map ini

Branch: refs/heads/main
Revision: ff7e3ac
Author: bmcdonald3
Link: Add an initialCapacity keyword argument to map initializers by bmcdonald3 · Pull Request #18634 · chapel-lang/chapel · GitHub
Log Message:

Merge pull request #18634 from bmcdonald3/map-resize

Add an initialCapacity keyword argument to map initializers

[ reviewed by @aconsroe-hpe - thanks! ]

This PR adds an initialCapacity argument to map initializers so that the user can set the starting capacity for the map. This number provided by the user is then rounded up to the nearest power of 2 table size and the starting size of the table will then be determined such that it will be able to hold initialCapacity elements before resizing. This means an initialCapacity of 12 corresponds to a starting table size of 32, since 32 is the smallest power of 2 table size that can hold 12 elements before resizing. The main benefit here is avoiding resizes when you already know how many elements your map will need.

Resolves https://github.com/Cray/chapel-private/issues/2626
Discussion issue: How should the initial capacity for map be set? · Issue #18620 · chapel-lang/chapel · GitHub

Modified Files:
A test/library/standard/Map/initial-capacity-2.chpl

A test/library/standard/Map/initial-capacity-2.good
A test/library/standard/Map/initial-capacity.chpl
A test/library/standard/Map/initial-capacity.good
A test/library/standard/Map/mapShrink.chpl
A test/library/standard/Map/mapShrink.good
M modules/internal/ChapelHashtable.chpl
M modules/standard/Map.chpl

Compare: https://github.com/chapel-lang/chapel/compare/324a419eca1e...ff7e3ace145f