summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseArray.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2013-07-12 17:46:45 -0700
committerDianne Hackborn <hackbod@google.com>2013-07-12 18:05:37 -0700
commitb993f41eb2f165425dfdf0f93ea0b1e354eca837 (patch)
tree7d505884a332ae0974b2b8f10d6e091cb865c159 /core/java/android/util/SparseArray.java
parent46db67cf7f974d4918c5c73ffc41d7058b74ccf0 (diff)
Update SparseArray docs to be more informative.
Change-Id: I5d8d17d46a69ccdcf6b29f93be3d44addd80ab61
Diffstat (limited to 'core/java/android/util/SparseArray.java')
-rw-r--r--core/java/android/util/SparseArray.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/core/java/android/util/SparseArray.java b/core/java/android/util/SparseArray.java
index 001fc5bcbbb6..0e013c376303 100644
--- a/core/java/android/util/SparseArray.java
+++ b/core/java/android/util/SparseArray.java
@@ -20,8 +20,25 @@ import com.android.internal.util.ArrayUtils;
/**
* SparseArrays map integers to Objects. Unlike a normal array of Objects,
- * there can be gaps in the indices. It is intended to be more efficient
- * than using a HashMap to map Integers to Objects.
+ * there can be gaps in the indices. It is intended to be more memory efficient
+ * than using a HashMap to map Integers to Objects, both because it avoids
+ * auto-boxing keys and its data structure doesn't rely on an extra entry object
+ * for each mapping.
+ *
+ * <p>Note that this container keeps its mappings in an array data structure,
+ * using a binary search to find keys. The implementation is not intended to be appropriate for
+ * data structures
+ * that may contain large numbers of items. It is generally slower than a traditional
+ * HashMap, since lookups require a binary search and adds and removes require inserting
+ * and deleting entries in the array. For containers holding up to hundreds of items,
+ * the performance difference is not significant, less than 50%.</p>
+ *
+ * <p>To help with performance, the container includes an optimization when removing
+ * keys: instead of compacting its array immediately, it leaves the removed entry marked
+ * as deleted. The entry can then be re-used for the same key, or compacted later in
+ * a single garbage collection step of all removed entries. This garbage collection will
+ * need to be performed at any time the array needs to be grown or the the map size or
+ * entry values are retrieved.</p>
*/
public class SparseArray<E> implements Cloneable {
private static final Object DELETED = new Object();