summaryrefslogtreecommitdiffstats
path: root/core/java/android/util
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2015-03-05 17:41:14 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-03-05 17:41:14 +0000
commitd833ba8d4e6d93744b3cd06a87b57b0a17864501 (patch)
tree25fd8a9d9e0447900bafdf5d88a92e0eb61b8c29 /core/java/android/util
parenta0bfb2d99f071aa42d2b04dcd77972d9a0888853 (diff)
parentecb48c16b7839bdcda84ac0ba7c61248b814eb71 (diff)
downloadframeworks_base-d833ba8d4e6d93744b3cd06a87b57b0a17864501.zip
frameworks_base-d833ba8d4e6d93744b3cd06a87b57b0a17864501.tar.gz
frameworks_base-d833ba8d4e6d93744b3cd06a87b57b0a17864501.tar.bz2
am ecb48c16: am 9c0ba24f: am 6695b992: Merge "Frameworks/base: Add removeAll for ArraySet"
* commit 'ecb48c16b7839bdcda84ac0ba7c61248b814eb71': Frameworks/base: Add removeAll for ArraySet
Diffstat (limited to 'core/java/android/util')
-rw-r--r--core/java/android/util/ArraySet.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java
index 68f725e..7da3941 100644
--- a/core/java/android/util/ArraySet.java
+++ b/core/java/android/util/ArraySet.java
@@ -475,6 +475,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