public class SparseIntIntArray extends Object
SparseArrays map ints to ints. Unlike a normal array of ints, there can be gaps in the indices.
Constructor and Description |
---|
SparseIntIntArray()
Creates a new SparseIntIntArray containing no mappings.
|
SparseIntIntArray(int cap)
Creates a new SparseIntIntArray containing no mappings that will not require any additional
memory allocation to store the specified number of mappings.
|
Modifier and Type | Method and Description |
---|---|
int |
append(int key,
int value)
Puts a key/value pair into the array, optimizing for the case where the key is greater than
all existing keys in the array.
|
int |
binarySearch(int key)
Warning: returns ~index and not -(index+1) like trove and jdk do
|
void |
clear()
Removes all key-value mappings from this SparseIntIntArray.
|
int |
get(int key)
Gets the Object mapped from the specified key, or
null if no such mapping has
been made. |
int |
getSize()
Returns the number of key-value mappings that this SparseIntIntArray currently stores.
|
int |
keyAt(int index)
Given an index in the range
0...size()-1 , returns the key from the
index th key-value mapping that this SparseIntIntArray stores. |
int |
put(int key,
int value)
Adds a mapping from the specified key to the specified value, replacing the previous mapping
from the specified key if there was one.
|
void |
remove(int key)
Removes the mapping from the specified key, if there was any.
|
void |
setKeyAt(int index,
int key)
Given an index in the range
0...size()-1 , sets a new key for the
index th key-value mapping that this SparseIntIntArray stores. |
void |
setValueAt(int index,
int value)
Given an index in the range
0...size()-1 , sets a new value for the
index th key-value mapping that this SparseIntIntArray stores. |
String |
toString() |
int |
valueAt(int index)
Given an index in the range
0...size()-1 , returns the value from the
index th key-value mapping that this SparseIntIntArray stores. |
public SparseIntIntArray()
public SparseIntIntArray(int cap)
public int get(int key)
null
if no such mapping has
been made.public void remove(int key)
public int put(int key, int value)
public int getSize()
public int keyAt(int index)
0...size()-1
, returns the key from the
index
th key-value mapping that this SparseIntIntArray stores.public void setKeyAt(int index, int key)
0...size()-1
, sets a new key for the
index
th key-value mapping that this SparseIntIntArray stores.public int valueAt(int index)
0...size()-1
, returns the value from the
index
th key-value mapping that this SparseIntIntArray stores.public void setValueAt(int index, int value)
0...size()-1
, sets a new value for the
index
th key-value mapping that this SparseIntIntArray stores.public void clear()
public int append(int key, int value)
public int binarySearch(int key)
Copyright © 2012–2016. All rights reserved.