From b759dcad7dfc723942e9c6da8dbdace2d343fe17 Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Wed, 13 May 2009 00:57:39 +0000 Subject: [PATCH] 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 --- src/java/com/samskivert/util/ArrayIntSet.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/java/com/samskivert/util/ArrayIntSet.java b/src/java/com/samskivert/util/ArrayIntSet.java index 2f745bab..f99e61a7 100644 --- a/src/java/com/samskivert/util/ArrayIntSet.java +++ b/src/java/com/samskivert/util/ArrayIntSet.java @@ -41,8 +41,24 @@ public class ArrayIntSet extends AbstractSet 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++]; + } + } + } } /**