public class SharedStrings extends Object implements Closeable
For large files, it is impossible to load all data into the memory and get it by index. The current practice is to partition and divide the data into three areas: forward, backward, and hot. The newly read data is placed in the forward area, if not found in forward area, go to the backward area to find, finally go to the hot area to find it. If not found in the three areas, press the ward will be re-load in to the forward area. The original forwarding area data is copied to the backward area. The blocks loaded twice will be marked, the marked blocks will be placed in the hot area when they are repeatedly read, and the hot area will be eliminated by the LRU page replacement algorithm.
| 构造器和说明 |
|---|
SharedStrings(IndexSharedStringTable sst,
int cacheSize,
int hotSize)
Constructs a SharedStrings with a
IndexSharedStringTable |
SharedStrings(Path sstPath,
int cacheSize,
int hotSize)
Constructs a SharedString with the xml path, please call
load() after instance |
SharedStrings(String[] data)
Constructs a SharedStrings containing the elements of the
specified data array
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
close stream and free space
|
String |
get(int index)
Getting the strings value by index
|
SharedStrings |
load()
Load the sharedString.xml file and instance word cache
|
protected int |
readData()
Read data from main reader
forward only
|
protected void |
readMore()
Load string record from xml
|
int |
size() |
static int |
tableSizeFor(int cap)
Returns a power of two size for the given target capacity.
|
String |
toString() |
public SharedStrings(String[] data)
data - the shared stringspublic SharedStrings(Path sstPath, int cacheSize, int hotSize)
load() after instancesstPath - the xml file pathcacheSize - the number of word per loadhotSize - the number of high frequency wordpublic SharedStrings(IndexSharedStringTable sst, int cacheSize, int hotSize) throws IOException
IndexSharedStringTablesst - IndexSharedStringTablecacheSize - the number of word per loadhotSize - the number of high frequency wordIOException - if I/O error occur.public int size()
public static int tableSizeFor(int cap)
cap - the custom buffer sizepublic SharedStrings load() throws IOException
SharedStringsIOException - if io error occurpublic String get(int index)
index - the index of SharedStringTableprotected void readMore()
protected int readData()
throws IOException
IOException - if I/O error occurpublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionCopyright © 2022. All rights reserved.