-
Notifications
You must be signed in to change notification settings - Fork 142
Magic Factors
Roman Leventov edited this page May 13, 2016
·
4 revisions
If array list or hash container has growth factor gf, it's expected memory footprint is gf * log(gf) / (gf - 1) (slots per element) and expected number of reinsertions during grows is gf * log(gf) / (gf - 1)^2 (reinsertions per element). In particular:
| Growth Factor | Memory Footprint | Reinsertions |
|---|---|---|
| 1.5 | 1.21 | 2.43 |
| 2.0 | 1.38 | 1.38 |
| 3.0 | 1.64 | 0.82 |
For example, average effective load factor of hash containers with formal load factor 0.5 and default growth factor 2.0 is 0.5 / 1.38 = 0.36.
Reinsertions into array list are very cheap (Arrays.copyOf), reinsertions into hash container are only aboout 30% cheaper than ordinary insertions.