commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-839) ArrayUtils removeElements methods use unnecessary HashSet
Date Mon, 01 Oct 2012 00:36:07 GMT

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

Sebb commented on LANG-839:
---------------------------

Using BitSet will clearly use less memory than HashSet or even an int[] array, so would also
reduce memory for the methods that currently clone the index array.

It remains to be seen whether the overhead of creating and using the BitSet is more or less
than cloning and sorting the array.
                
> ArrayUtils removeElements methods use unnecessary HashSet
> ---------------------------------------------------------
>
>                 Key: LANG-839
>                 URL: https://issues.apache.org/jira/browse/LANG-839
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Sebb
>            Priority: Minor
>         Attachments: LANG-839.patch
>
>
> The removeElements() methods use a HashSet to collect the indexes that need removing.
> This requires creating Integer objects for each index, and the HashSet then has to be
converted into an int[] array.
> It would be more efficient to store the entries in an actual int[] array.
> The maximum size of this is the length of the values array (or the length of the input
array if that is shorter).
> The array must be truncated before calling the private removeAll() method; this can be
done with Arrays.copyOf(x[], length).
> However, if the arrays are very large, and most of the values do not appear in the input,
this might result in using more memory than the HashSet implementation.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message