commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CSV-184) CSVRecord toMap Method(LoadFactor for HashMap)
Date Tue, 31 May 2016 07:00:19 GMT

    [ https://issues.apache.org/jira/browse/CSV-184?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15307312#comment-15307312
] 

Gary Gregory edited comment on CSV-184 at 5/31/16 7:00 AM:
-----------------------------------------------------------

That's not how a HashMap works. Once the map is over its load factory, its internal size doubles.

For example:

{code:java}
Map m = new java.util.HashMap();
{code}
The map is size() 0 and LF 75% but internally it is size 16.

{code:java}
for (int i = 0; i < 12; i++) {
    m.put(i,i);
}
{code}The map now is size() 11 and the internal size is still < 75% and still internally
size 16.

{code:java}
m.put(12,12);
{code}
The new element puts the map over the LF% so the map now is size() 12 and internally it doubles
to 32.



was (Author: garydgregory):
That's not how a HashMap works. Once the map is over its load factory, its internal size doubles.

For example:

Map m = new java.util.HashMap();
//The map is size() 0 and LF 75% but internally it is size 16.

for (int i = 0; i < 12; i++) {
    m.put(i,i);
}
//The map now is size() 11 and the internal size is still < 75% and still internally size
16.

m.put(12,12);

//The new element puts the map over the LF% so the map now is size() 12 and internally it
doubles to 32.


> CSVRecord toMap Method(LoadFactor for HashMap)
> ----------------------------------------------
>
>                 Key: CSV-184
>                 URL: https://issues.apache.org/jira/browse/CSV-184
>             Project: Commons CSV
>          Issue Type: Improvement
>          Components: Parser
>    Affects Versions: 1.4
>            Reporter: Gaurav Agarwal
>            Priority: Minor
>
> Set loadFactor for Hashmap Object to 1(Default : 0.75) as currently it will always resize
the map when we are putting entries in it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message