nz.util
Class PagedArray
java.lang.Object
|
+--nz.util.PagedArray
- All Implemented Interfaces:
- java.io.Serializable
- public class PagedArray
- extends java.lang.Object
- implements java.io.Serializable
Very simple sparse array class that maintains
a set of pages, so that a sparse array can be
reasonably fast but not too big. This one
holds object pointers. This is probably
not as efficient as a true sparse array, but
it is simpler. The page size is adjustable,
but must be a power of 2; 32 and 64 are usually
reasonable choices.
The current implementation is wasteful of space
for arrays where the indices are very spread out.
It is efficiently only for arrays where values
tend to be set in tight little clusters.
- See Also:
- Serialized Form
Constructor Summary |
PagedArray()
Create a PagedArray of size upto 65536, with
a page size of 128, and an initialized page set
of 2. |
PagedArray(int maxsiz,
int indexbits,
int initcnt)
Create a PagedArray of maximum size maxsiz, with
a page size of 2^indexbits, and an initialized page
set of initcnt. |
Method Summary |
java.lang.Object |
get(int n)
Get an item from the PagedArray. |
static void |
main(java.lang.String[] args)
|
int |
next(int n)
Get the next valid index after a given one, or
return -1 if there are no more. |
void |
put(int n,
java.lang.Object v)
Put an item into the PagedArray. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
pageCountTotal
public static int pageCountTotal
PagedArray
public PagedArray()
- Create a PagedArray of size upto 65536, with
a page size of 128, and an initialized page set
of 2.
PagedArray
public PagedArray(int maxsiz,
int indexbits,
int initcnt)
- Create a PagedArray of maximum size maxsiz, with
a page size of 2^indexbits, and an initialized page
set of initcnt.
- Parameters:
maxsiz
- maximum size of this sparse arrayindexbits
- number of bits in the index within a page (usually 4-8)initcnt
- how many of the bins to initialize (usually 0)
get
public final java.lang.Object get(int n)
- Get an item from the PagedArray. Returns null
if that index in the array is empty.
- Parameters:
n
- array index
next
public int next(int n)
- Get the next valid index after a given one, or
return -1 if there are no more. A valid index is one where
non-null value is stored.
- Parameters:
n
- an array index
put
public final void put(int n,
java.lang.Object v)
- Put an item into the PagedArray. Any old value
is overwritten. May cause the array to grow,
or even portions of the pages array to be copied.
- Parameters:
n
- array indexv
- new value in the array
main
public static void main(java.lang.String[] args)