Top Description Inners Fields Constructors Methods
org.apache.xerces.util

public Class SoftReferenceSymbolTable

extends SymbolTable
Class Inheritance
Imports
java.lang.ref.ReferenceQueue, .SoftReference

This symbol table uses SoftReferences to its String entries, which means that table entries that have no references to them can be garbage collected when memory is needed. Thus, in documents with very very large numbers of unique strings, using this SymbolTable will prevent an out of memory error from occurring.
Author
Peter McCracken, IBM
Version
$Id: SoftReferenceSymbolTable.java 1358350 2012-07-06 19:04:35Z mrglavas $
See Also
SymbolTable

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
SoftReferenceSymbolTable.SREntry

This class is a symbol table entry.

protected static class

Field Summary

Modifier and TypeField and Description
protected SoftReferenceSymbolTable.SREntry[]
private final ReferenceQueue<T>
Inherited from org.apache.xerces.util.SymbolTable:
fCollisionThresholdfCountfHashMultipliersfLoadFactorfTableSizefThresholdMAX_HASH_COLLISIONSMULTIPLIERS_MASKMULTIPLIERS_SIZETABLE_SIZE

Constructor Summary

AccessConstructor and Description
public
SoftReferenceSymbolTable(int
the initial capacity of the SymbolTable.
initialCapacity
,
float
the load factor of the SymbolTable.
loadFactor
)

Constructs a new, empty SymbolTable with the specified initial capacity and the specified load factor.

public
SoftReferenceSymbolTable(int
the initial capacity of the hashtable.
initialCapacity
)

Constructs a new, empty SymbolTable with the specified initial capacity and default load factor, which is 0.75.

public
SoftReferenceSymbolTable()

Constructs a new, empty SymbolTable with a default initial capacity (101) and load factor, which is 0.75.

Method Summary

Modifier and TypeMethod and Description
public String
addSymbol(String
The new symbol.
symbol
)

Overrides org.apache.xerces.util.SymbolTable.addSymbol.

Adds the specified symbol to the symbol table and returns a reference to the unique symbol.
public String
addSymbol(char[]
The buffer containing the new symbol.
buffer
,
int
The offset into the buffer of the new symbol.
offset
,
int
The length of the new symbol in the buffer.
length
)

Overrides org.apache.xerces.util.SymbolTable.addSymbol.

Adds the specified symbol to the symbol table and returns a reference to the unique symbol.
private String
addSymbol0(String symbol, int bucket, int collisionCount)

Hides org.apache.xerces.util.SymbolTable.addSymbol0.

private String
addSymbol0(char[] buffer, int offset, int length, int bucket, int collisionCount)

Hides org.apache.xerces.util.SymbolTable.addSymbol0.

private void
clean()

Removes stale symbols from the table.

protected void
compact()

Reduces the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries in a more memory efficient way.

public boolean
containsSymbol(String
The symbol to look for.
symbol
)

Overrides org.apache.xerces.util.SymbolTable.containsSymbol.

Returns true if the symbol table already contains the specified symbol.
public boolean
containsSymbol(char[]
The buffer containing the symbol to look for.
buffer
,
int
The offset into the buffer.
offset
,
int
The length of the symbol in the buffer.
length
)

Overrides org.apache.xerces.util.SymbolTable.containsSymbol.

Returns true if the symbol table already contains the specified symbol.
protected void
rebalance()

Overrides org.apache.xerces.util.SymbolTable.rebalance.

Randomly selects a new hash function and reorganizes this SymbolTable in order to more evenly distribute its entries across the table.
protected void
rehash()

Overrides org.apache.xerces.util.SymbolTable.rehash.

Increases the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries more efficiently.
private void
private void
Inherited from org.apache.xerces.util.SymbolTable:
hashhash

Field Detail

fBucketsback to summary
protected SoftReferenceSymbolTable.SREntry[] fBuckets

Hides org.apache.xerces.util.SymbolTable.fBuckets.

fReferenceQueueback to summary
private final ReferenceQueue<T> fReferenceQueue

Constructor Detail

SoftReferenceSymbolTableback to summary
public SoftReferenceSymbolTable(int initialCapacity, float loadFactor)

Constructs a new, empty SymbolTable with the specified initial capacity and the specified load factor.

Parameters
initialCapacity:int

the initial capacity of the SymbolTable.

loadFactor:float

the load factor of the SymbolTable.

Exceptions
IllegalArgumentException:
if the initial capacity is less than zero, or if the load factor is nonpositive.
SoftReferenceSymbolTableback to summary
public SoftReferenceSymbolTable(int initialCapacity)

Constructs a new, empty SymbolTable with the specified initial capacity and default load factor, which is 0.75.

Parameters
initialCapacity:int

the initial capacity of the hashtable.

Exceptions
IllegalArgumentException:
if the initial capacity is less than zero.
SoftReferenceSymbolTableback to summary
public SoftReferenceSymbolTable()

Constructs a new, empty SymbolTable with a default initial capacity (101) and load factor, which is 0.75.

Method Detail

addSymbolback to summary
public String addSymbol(String symbol)

Overrides org.apache.xerces.util.SymbolTable.addSymbol.

Adds the specified symbol to the symbol table and returns a reference to the unique symbol. If the symbol already exists, the previous symbol reference is returned instead, in order guarantee that symbol references remain unique.

Parameters
symbol:String

The new symbol.

addSymbolback to summary
public String addSymbol(char[] buffer, int offset, int length)

Overrides org.apache.xerces.util.SymbolTable.addSymbol.

Adds the specified symbol to the symbol table and returns a reference to the unique symbol. If the symbol already exists, the previous symbol reference is returned instead, in order guarantee that symbol references remain unique.

Parameters
buffer:char[]

The buffer containing the new symbol.

offset:int

The offset into the buffer of the new symbol.

length:int

The length of the new symbol in the buffer.

addSymbol0back to summary
private String addSymbol0(String symbol, int bucket, int collisionCount)

Hides org.apache.xerces.util.SymbolTable.addSymbol0.

addSymbol0back to summary
private String addSymbol0(char[] buffer, int offset, int length, int bucket, int collisionCount)

Hides org.apache.xerces.util.SymbolTable.addSymbol0.

cleanback to summary
private void clean()

Removes stale symbols from the table.

compactback to summary
protected void compact()

Reduces the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries in a more memory efficient way. This method is called automatically when the number of keys in the SymbolTable drops below 25% of this hashtable's load factor (as a result of SoftReferences which have been cleared).

containsSymbolback to summary
public boolean containsSymbol(String symbol)

Overrides org.apache.xerces.util.SymbolTable.containsSymbol.

Returns true if the symbol table already contains the specified symbol.

Parameters
symbol:String

The symbol to look for.

containsSymbolback to summary
public boolean containsSymbol(char[] buffer, int offset, int length)

Overrides org.apache.xerces.util.SymbolTable.containsSymbol.

Returns true if the symbol table already contains the specified symbol.

Parameters
buffer:char[]

The buffer containing the symbol to look for.

offset:int

The offset into the buffer.

length:int

The length of the symbol in the buffer.

rebalanceback to summary
protected void rebalance()

Overrides org.apache.xerces.util.SymbolTable.rebalance.

Randomly selects a new hash function and reorganizes this SymbolTable in order to more evenly distribute its entries across the table. This method is called automatically when the number keys in one of the SymbolTable's buckets exceeds the given collision threshold.

rehashback to summary
protected void rehash()

Overrides org.apache.xerces.util.SymbolTable.rehash.

Increases the capacity of and internally reorganizes this SymbolTable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the SymbolTable exceeds this hashtable's capacity and load factor.

rehashCommonback to summary
private void rehashCommon(final int newCapacity)

Hides org.apache.xerces.util.SymbolTable.rehashCommon.

removeEntryback to summary
private void removeEntry(SoftReferenceSymbolTable.SREntry entry)
org.apache.xerces.util back to summary

protected final Class SoftReferenceSymbolTable.SREntry

extends SoftReference
Class Inheritance

This class is a symbol table entry. Each entry acts as a node in a doubly-linked list. The "SR" stands for SoftReference.

Field Summary

Modifier and TypeField and Description
public int
bucket

The bucket this entry is contained in; -1 if it has been removed from the table.

public SoftReferenceSymbolTable.SREntry
next

Hides java.lang.ref.Reference.next.

The next entry.
public SoftReferenceSymbolTable.SREntry
prev

The previous entry.

Constructor Summary

AccessConstructor and Description
public
SREntry(String internedSymbol, SoftReferenceSymbolTable.SREntry next, int bucket, ReferenceQueue<T> q)

Constructs a new entry from the specified symbol and next entry reference.

public
SREntry(String internedSymbol, char[] ch, int offset, int length, SoftReferenceSymbolTable.SREntry next, int bucket, ReferenceQueue<T> q)

Constructs a new entry from the specified symbol information and next entry reference.

Method Summary

Modifier and TypeMethod and Description
private void
Inherited from java.lang.ref.SoftReference:
get

Field Detail

bucketback to summary
public int bucket

The bucket this entry is contained in; -1 if it has been removed from the table.

nextback to summary
public SoftReferenceSymbolTable.SREntry next

Hides java.lang.ref.Reference.next.

The next entry.

prevback to summary
public SoftReferenceSymbolTable.SREntry prev

The previous entry.

Constructor Detail

SREntryback to summary
public SREntry(String internedSymbol, SoftReferenceSymbolTable.SREntry next, int bucket, ReferenceQueue<T> q)

Constructs a new entry from the specified symbol and next entry reference.

SREntryback to summary
public SREntry(String internedSymbol, char[] ch, int offset, int length, SoftReferenceSymbolTable.SREntry next, int bucket, ReferenceQueue<T> q)

Constructs a new entry from the specified symbol information and next entry reference.

Method Detail

initializeback to summary
private void initialize(SoftReferenceSymbolTable.SREntry next, int bucket)
org.apache.xerces.util back to summary

protected final Class SoftReferenceSymbolTable.SREntryData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final char[]
public final String

Constructor Summary

AccessConstructor and Description
public
SREntryData(String internedSymbol)

public
SREntryData(String internedSymbol, char[] ch, int offset, int length)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charactersback to summary
public final char[] characters
symbolback to summary
public final String symbol

Constructor Detail

SREntryDataback to summary
public SREntryData(String internedSymbol)
SREntryDataback to summary
public SREntryData(String internedSymbol, char[] ch, int offset, int length)