org.tranche.hash
Class DiskBackedBigHashSet

java.lang.Object
  extended by org.tranche.hash.DiskBackedBigHashSet

public class DiskBackedBigHashSet
extends java.lang.Object

Splitting some of functionality from Jayson's SimpleDiskBackedBigHashList to a Set so that both classes behave in their expected manner.

Author:
Bryan E. Smith - bryanesmith@gmail.com

Field Summary
static int BUFFER_IN_MEMORY
           
 long filesBuffered
           
 
Constructor Summary
DiskBackedBigHashSet()
          Build a instance using a temp file.
DiskBackedBigHashSet(java.io.File fileForRecords)
          Provide a file used to store records on disk.
 
Method Summary
 void add(BigHash hash)
           
 void clear()
          Clears out all the hashes.
 void close()
          Close off resources.
 boolean contains(BigHash hash)
           
 void delete(BigHash hash)
           
 java.util.List get(long offset, long limit)
           
 int getTestBufferSize()
           
 boolean isAutoWriteBeforeCriticalOperation()
          If true, will write buffers to disk before the following operations:
 void setAutoWriteBeforeCriticalOperation(boolean autoWriteBeforeCriticalOperation)
          If true, will write buffers to disk before the following operations:
 void setTestBufferSize(int testBufferSize)
           
 int size()
          Note: this might return an inaccurate result under two conditions:
 int size(boolean isAllowEstimate)
          Offers caller more choice than size().
 BigHash[] toArray()
          Converts contents to array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filesBuffered

public long filesBuffered

BUFFER_IN_MEMORY

public static final int BUFFER_IN_MEMORY
See Also:
Constant Field Values
Constructor Detail

DiskBackedBigHashSet

public DiskBackedBigHashSet()

Build a instance using a temp file.


DiskBackedBigHashSet

public DiskBackedBigHashSet(java.io.File fileForRecords)

Provide a file used to store records on disk.

Primary use case is when information needs to persist across instances.

Method Detail

clear

public void clear()
           throws java.lang.Exception

Clears out all the hashes.

Throws:
java.lang.Exception - Since must delete and create files.

add

public final void add(BigHash hash)

delete

public final void delete(BigHash hash)

size

public int size()

Note: this might return an inaccurate result under two conditions:

The result will be accurate is autoWriteBeforeCriticalOperation is set to true.

Returns:
Number of BigHash's in set

size

public int size(boolean isAllowEstimate)

Offers caller more choice than size(). Caller decides whether estimate is good enough, which can really save some time.

Parameters:
isAllowEstimate - If true, skip expensive operations that guarentee exact size. Estimates are not reliable, but can be useful if an estimate is appropriate.
Returns:
The size of the collection, either actual or estimate.

contains

public final boolean contains(BigHash hash)
                       throws java.lang.Exception
Throws:
java.lang.Exception

get

public final java.util.List get(long offset,
                                long limit)
                         throws java.lang.Exception
Parameters:
offset -
limit -
Returns:
Throws:
java.lang.Exception

close

public final void close()

Close off resources.

If collection uses a temporary file, delete. Else flush contents for next use.


getTestBufferSize

public int getTestBufferSize()
Returns:

setTestBufferSize

public void setTestBufferSize(int testBufferSize)
Parameters:
testBufferSize -

toArray

public BigHash[] toArray()
                  throws java.lang.Exception

Converts contents to array. Note: the purpose of this collection is to disk back to avoid tremendous memory overhead. Only use if know collection will fit in memory.

Returns:
Throws:
java.lang.Exception

isAutoWriteBeforeCriticalOperation

public boolean isAutoWriteBeforeCriticalOperation()

If true, will write buffers to disk before the following operations:

Returns:
True if writing buffers to disk before critical operations, false otherwise

setAutoWriteBeforeCriticalOperation

public void setAutoWriteBeforeCriticalOperation(boolean autoWriteBeforeCriticalOperation)

If true, will write buffers to disk before the following operations:

Parameters:
autoWriteBeforeCriticalOperation - True if writing buffers to disk before critical operations, false otherwise


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