org.tranche.hash
Class DiskBackedBigHashList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<BigHash>
          extended by org.tranche.hash.DiskBackedBigHashList
All Implemented Interfaces:
java.lang.Iterable<BigHash>, java.util.Collection<BigHash>, java.util.List<BigHash>

public class DiskBackedBigHashList
extends java.util.AbstractList<BigHash>

A list that stores BigHash objects. This is a memory-friendly method that commits portions of list to disk.

Every certain number of BigHash records, records are committed to disk, and the number of BigHash entries in memory are always less than the number of records stored in each partition file.

You can find out number of records stored per partition by calling static method DiskBackedBigHashList.RECORDS_PER_PARTITION().

Author:
Bryan Smith

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
DiskBackedBigHashList()
           
 
Method Summary
 boolean add(BigHash hash)
          Append hash to list.
 void close()
           
 boolean contains(BigHash hash)
          Returns true if this contains a given Hash
 void destroy()
          Deprecated. Use close
 java.io.File directory()
          Returns directory that holds partition files
protected  void finalize()
          When done with list, destroy records on disk.
 BigHash get(int index)
          Get BigHash at specified index.
static int getRecordsPerPartition()
          Retrieve number of records per partition.
 java.util.Iterator<BigHash> iterator()
          Returns an iterator for list.
 int paritionsOnDisk()
          Returns number of partitions on disk.
 boolean recordOnDisk(int index)
          Returns true if on disk, else returns false.
 int recordsInMemory()
          Returns number of records in memory.
 int recordsOnDisk()
          Returns number of records in partitions on disk.
static int recordsPerPartition()
          Returns number of BigHash entries stored in each disk partition.
 BigHash remove(int index)
          CURRENTLY UNIMPLEMENTED
static void setRecordsPerPartition(int aRECORDS_PER_PARTITION)
          Set number of records per partition.
 int size()
          Returns size of list.
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

DiskBackedBigHashList

public DiskBackedBigHashList()
                      throws java.io.IOException
Throws:
java.io.IOException
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
When done with list, destroy records on disk.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

close

public void close()

destroy

public void destroy()
Deprecated. Use close

Explicity destroy the disk-backed collection. If don't, GC will garbage collect OR temp dir cleaned out when tool reran.


recordsPerPartition

public static int recordsPerPartition()
Returns number of BigHash entries stored in each disk partition.

Returns:
int Number of BigHash entries per partition.

directory

public java.io.File directory()
Returns directory that holds partition files

Returns:
File The directory holding partition files.

size

public int size()
Returns size of list.

Specified by:
size in interface java.util.Collection<BigHash>
Specified by:
size in interface java.util.List<BigHash>
Specified by:
size in class java.util.AbstractCollection<BigHash>
Returns:
int Size of list.

recordsInMemory

public int recordsInMemory()
Returns number of records in memory. (The rest are on disk.)

Returns:
int Number of BigHash records in memory

recordsOnDisk

public int recordsOnDisk()
Returns number of records in partitions on disk. (The rest are in memory.)

Returns:
int Number of BigHash records on disk (in partitions)

paritionsOnDisk

public int paritionsOnDisk()
Returns number of partitions on disk.

Returns:
int Number of partitions on disk.

contains

public boolean contains(BigHash hash)
Returns true if this contains a given Hash

Parameters:
hash - BigHash
Returns:
true if parameter appears in list.

add

public boolean add(BigHash hash)
Append hash to list.

Specified by:
add in interface java.util.Collection<BigHash>
Specified by:
add in interface java.util.List<BigHash>
Overrides:
add in class java.util.AbstractList<BigHash>
Parameters:
hash - A BigHash to add to list.

get

public BigHash get(int index)
Get BigHash at specified index.

Specified by:
get in interface java.util.List<BigHash>
Specified by:
get in class java.util.AbstractList<BigHash>
Parameters:
index - Index of BigHash.
Returns:
BigHash The BigHash.

recordOnDisk

public boolean recordOnDisk(int index)
Returns true if on disk, else returns false. Throws a RuntimeException if index out of bounds.

Parameters:
index - Index of hash
Returns:
boolean True if on disk, false if in memory.

remove

public BigHash remove(int index)
CURRENTLY UNIMPLEMENTED

Specified by:
remove in interface java.util.List<BigHash>
Overrides:
remove in class java.util.AbstractList<BigHash>
Parameters:
index - Index of BigHash.
Returns:
BigHash The BigHash.

iterator

public java.util.Iterator<BigHash> iterator()

Returns an iterator for list.

Specified by:
iterator in interface java.lang.Iterable<BigHash>
Specified by:
iterator in interface java.util.Collection<BigHash>
Specified by:
iterator in interface java.util.List<BigHash>
Overrides:
iterator in class java.util.AbstractList<BigHash>
Returns:
Iterator

getRecordsPerPartition

public static int getRecordsPerPartition()
Retrieve number of records per partition.

Returns:

setRecordsPerPartition

public static void setRecordsPerPartition(int aRECORDS_PER_PARTITION)
Set number of records per partition.

Parameters:
aRECORDS_PER_PARTITION -


This code is free for use both commercially and non-commercially as stated in the project's license