diff options
author | Andreas Gampe <agampe@google.com> | 2015-03-05 17:10:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-05 17:10:31 +0000 |
commit | 6695b9920d15f8d9a17d6b0c66b863d1c2e38584 (patch) | |
tree | ef2e644ce8bbd644172350df499bc681236179ae | |
parent | 165c25641ccedf6447d09dfec00f485df1361c35 (diff) | |
parent | f9345e93db82adf8eaa2afc731933462d7876b13 (diff) | |
download | frameworks_base-6695b9920d15f8d9a17d6b0c66b863d1c2e38584.zip frameworks_base-6695b9920d15f8d9a17d6b0c66b863d1c2e38584.tar.gz frameworks_base-6695b9920d15f8d9a17d6b0c66b863d1c2e38584.tar.bz2 |
Merge "Frameworks/base: Add removeAll for ArraySet"
-rw-r--r-- | core/java/android/util/ArraySet.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java index 423e48b..3214b22 100644 --- a/core/java/android/util/ArraySet.java +++ b/core/java/android/util/ArraySet.java @@ -468,6 +468,26 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { } /** + * Perform a {@link #remove(Object)} of all values in <var>array</var> + * @param array The array whose contents are to be removed. + */ + public boolean removeAll(ArraySet<? extends E> array) { + // TODO: If array is sufficiently large, a marking approach might be beneficial. In a first + // pass, use the property that the sets are sorted by hash to make this linear passes + // (except for hash collisions, which means worst case still n*m), then do one + // collection pass into a new array. This avoids binary searches and excessive memcpy. + final int N = array.mSize; + + // Note: ArraySet does not make thread-safety guarantees. So instead of OR-ing together all + // the single results, compare size before and after. + final int originalSize = mSize; + for (int i = 0; i < N; i++) { + remove(array.valueAt(i)); + } + return originalSize != mSize; + } + + /** * Return the number of items in this array map. */ @Override |