org.jplot2d.util
Class SparseArray<E>
- java.lang.Object
-
- org.jplot2d.util.SparseArray<E>
-
- All Implemented Interfaces:
- java.lang.Cloneable
public class SparseArray<E> extends java.lang.Object implements java.lang.CloneableSparseArrays 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.
-
-
Constructor Summary
Constructors Constructor and Description SparseArray()Creates a new SparseArray containing no mappings.SparseArray(int initialCapacity)Creates a new SparseArray containing no mappings that will not require any additional memory allocation to store the specified number of mappings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Removes all key-value mappings from this SparseArray.SparseArray<E>copy()Eget(int key)Gets the Object mapped from the specified key, ornullif no such mapping has been made.voidput(int key, E value)Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.voidremove(int key)Removes the mapping from the specified key, if there was any.intsize()Returns the number of key-value mappings that this SparseArray currently stores.
-
-
-
Constructor Detail
-
SparseArray
public SparseArray()
Creates a new SparseArray containing no mappings.
-
SparseArray
public SparseArray(int initialCapacity)
Creates a new SparseArray containing no mappings that will not require any additional memory allocation to store the specified number of mappings.
-
-
Method Detail
-
copy
public SparseArray<E> copy()
-
get
public E get(int key)
Gets the Object mapped from the specified key, ornullif no such mapping has been made.
-
remove
public void remove(int key)
Removes the mapping from the specified key, if there was any.
-
put
public void put(int key, E value)Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.
-
size
public int size()
Returns the number of key-value mappings that this SparseArray currently stores.
-
clear
public void clear()
Removes all key-value mappings from this SparseArray.
-
-
DMelt 3.0 © DataMelt by jWork.ORG