Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b993f41e authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Update SparseArray docs to be more informative.

Change-Id: I5d8d17d46a69ccdcf6b29f93be3d44addd80ab61
parent 46db67cf
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -34,8 +34,7 @@ import java.util.Set;
 * 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%.  For larger numbers of items
 * this data structure should be avoided.</p>
 * the performance difference is not significant, less than 50%.</p>
 *
 * <p><b>Note:</b> unlike {@link java.util.HashMap}, this container does not support
 * null keys.</p>
@@ -44,7 +43,7 @@ import java.util.Set;
 * standard Java containers it will shrink its array as items are removed from it.  Currently
 * you have no control over this shrinking -- if you set a capacity and then remove an
 * item, it may reduce the capacity to better match the current size.  In the future an
 * explicitly call to set the capacity should turn off this aggressive shrinking behavior.</p>
 * explicit call to set the capacity should turn off this aggressive shrinking behavior.</p>
 *
 * @hide
 */
+2 −3
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@ import java.util.Set;
 * that may contain large numbers of items.  It is generally slower than a traditional
 * HashSet, 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%.  For larger numbers of items
 * this data structure should be avoided.</p>
 * the performance difference is not significant, less than 50%.</p>
 *
 * <p><b>Note:</b> unlike {@link java.util.HashSet}, this container does not support
 * null values.</p>
@@ -43,7 +42,7 @@ import java.util.Set;
 * standard Java containers it will shrink its array as items are removed from it.  Currently
 * you have no control over this shrinking -- if you set a capacity and then remove an
 * item, it may reduce the capacity to better match the current size.  In the future an
 * explicitly call to set the capacity should turn off this aggressive shrinking behavior.</p>
 * explicit call to set the capacity should turn off this aggressive shrinking behavior.</p>
 *
 * @hide
 */
+19 −2
Original line number Diff line number Diff line
@@ -20,8 +20,25 @@ import com.android.internal.util.ArrayUtils;

/**
 * SparseArray mapping longs 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 Longs to Objects.
 * there can be gaps in the indices.  It is intended to be more memory efficient
 * than using a HashMap to map Longs 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 LongSparseArray<E> implements Cloneable {
    private static final Object DELETED = new Object();
+12 −2
Original line number Diff line number Diff line
@@ -22,8 +22,18 @@ import java.util.Arrays;

/**
 * Map of {@code long} to {@code long}. Unlike a normal array of longs, there
 * can be gaps in the indices. It is intended to be more efficient than using a
 * {@code HashMap}.
 * can be gaps in the indices. It is intended to be more memory efficient than using a
 * {@code HashMap}, both because it avoids
 * auto-boxing keys and values 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>
 *
 * @hide
 */
+19 −2
Original line number Diff line number Diff line
@@ -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();
Loading