public class StringCache extends Object
The StringCache is a N-way set associative cache which distributes all strings into buckets based on hash function and then uses LRU algorithm within each bucket. The StringCache is a thread-safe, asynchronous, wait-free data structure.
Constructor and Description |
---|
StringCache()
Creates a StringCache with default parameters.
|
StringCache(int size)
Creates a StringCache with the specified number of elements and default bucket size.
|
StringCache(int bucketNumber,
int bucketSize)
Creates a StringCache with the specified number of buckets and their size.
|
Modifier and Type | Method and Description |
---|---|
String |
get(char[] c)
Returns string from the cache that matches specified character sequence.
|
String |
get(char[] c,
int offset,
int length)
Returns string from the cache that matches specified character sequence.
|
String |
get(CharSequence cs)
Returns string from the cache that matches specified character sequence.
|
String |
get(CharSequence cs,
int offset,
int length)
Returns string from the cache that matches specified character sequence.
|
String |
get(String s)
Returns string from the cache that matches specified string.
|
String |
get(String s,
boolean copy)
Returns string from the cache that matches specified string.
|
String |
get(String s,
int offset,
int length)
Returns string from the cache that matches specified character sequence.
|
String |
getASCII(byte[] b)
Returns string from the cache that matches specified character sequence.
|
String |
getASCII(byte[] b,
int offset,
int length)
Returns string from the cache that matches specified character sequence.
|
String |
getShortString(long code)
Returns string from the cache that matches specified character sequence.
|
String |
toString() |
public StringCache()
public StringCache(int size)
size
- the number of elementsIllegalArgumentException
- if size is not positive or result in too large cachepublic StringCache(int bucketNumber, int bucketSize)
NOTE: cache uses linear search within each bucket, so do not use very large bucket sizes.
bucketNumber
- the number of bucketsbucketSize
- the size of each bucketIllegalArgumentException
- if parameters are not positive or result in too large cachepublic String get(String s, boolean copy)
public String get(String s, int offset, int length)
public String get(CharSequence cs)
public String get(CharSequence cs, int offset, int length)
public String get(char[] c)
public String get(char[] c, int offset, int length)
public String getASCII(byte[] b)
public String getASCII(byte[] b, int offset, int length)
public String getShortString(long code)
ShortString
class.Copyright © 2002–2025 Devexperts LLC. All rights reserved.