We must assign the _size when setting the array like this.

Also: added duplicate-removing code to preserve Set-ness.
Suddenly this is all looking like a "code-weirding" optimization.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2557 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray.j.greenwell
2009-05-13 00:57:39 +00:00
parent a0e960449c
commit b759dcad7d
+17 -1
View File
@@ -41,8 +41,24 @@ public class ArrayIntSet extends AbstractSet<Integer>
public ArrayIntSet (int[] values)
{
this(values.length);
System.arraycopy(values, 0, _values, 0, values.length);
_size = values.length;
System.arraycopy(values, 0, _values, 0, _size);
Arrays.sort(_values);
// remove duplicates
if (_size > 1) {
int last = _values[0];
for (int ii = 1; ii < _size; ) {
if (values[ii] == last) {
// shift everything down 1
_size--;
System.arraycopy(_values, ii + 1, _values, ii, _size - ii);
} else {
last = values[ii++];
}
}
}
}
/**