[
https://issues.apache.org/jira/browse/LANG-839?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13466201#comment-13466201
]
Sebb commented on LANG-839:
---------------------------
An alternative implementation might be to use BitSet, as indexes are never
negative.
This requires much reduced storage as the 32-bit ints are stored as 1 bit each.
If this was also used in the private removeAll() method, it would remove the
need to check for duplicates, and there would be no need to sort the int array.
BitSet offers nextSetBit and nextClearBit methods but does not offer the
reverse, so either the copy algorithm would need to be reversed, or the indexes
could be subtracted from the array length before storage.
Conversion to using BitSet would also avoid the need to clone external arrays
as they would no longer need sorting.
> 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
>
> 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