$darkmode
DENOPTIM
|
Class meant to collect unique strings without leading to memory overflow. More...
Public Member Functions | |
SizeControlledSet (int maxSize, String memoryFile, String allUIDsFile) | |
Constructor for a size-controlled storage of unique Strings. More... | |
synchronized boolean | addNewUniqueEntry (String entry) throws IOException |
Checks if the given entry is already container in the set of known entries and, if not, adds it to the set. More... | |
synchronized boolean | contains (String entry) throws IOException |
Checks if an entry is contained in this collection. More... | |
synchronized int | size () |
Returns the number of unique entries. More... | |
Private Attributes | |
int | maxSize |
Maximum size of the set. More... | |
File | dataOnDisk |
The file used to deal with entries that do not fit in the maximum size of this set. More... | |
File | allData |
The file used to store all entries on disk. More... | |
boolean | usingDisk = false |
Flag signalling the use of the disk. More... | |
int | entriesInFile = 0 |
Number of entries written to file. More... | |
Set< String > | data |
The actual data collection. More... | |
Class meant to collect unique strings without leading to memory overflow.
This class wraps a synchronised set and controls the size of such set. If we need to deal with more elements than the maximum size, then the entries that do not fit in the maximum size are written to disk and dealt with by I/O operations.
Definition at line 39 of file SizeControlledSet.java.
denoptim.utils.SizeControlledSet.SizeControlledSet | ( | int | maxSize, |
String | memoryFile, | ||
String | allUIDsFile | ||
) |
Constructor for a size-controlled storage of unique Strings.
maxSize | the maximum size of entries to keep in the memory. |
memoryFile | the pathname to a non-existing file that might be used to store entries on disk in case the maximum size is not sufficient. |
allUIDsFile | the pathname to a file where all entries are collected. It can be null, in which case we do not write every entry to file. |
Definition at line 84 of file SizeControlledSet.java.
References denoptim.utils.SizeControlledSet.data, and denoptim.utils.SizeControlledSet.maxSize.
synchronized boolean denoptim.utils.SizeControlledSet.addNewUniqueEntry | ( | String | entry | ) | throws IOException |
Checks if the given entry is already container in the set of known entries and, if not, adds it to the set.
This method adds the entry to memory or disk depending on the maximum memory footprint defined at construction time.
entry | the entry to search for and, possibly, to add to the set. |
true
if the set did not already contain the entry, which was then added. IOException | when handling of the memory written on disk returns exception. |
Definition at line 106 of file SizeControlledSet.java.
References denoptim.utils.SizeControlledSet.allData, denoptim.utils.SizeControlledSet.data, denoptim.utils.SizeControlledSet.dataOnDisk, denoptim.utils.SizeControlledSet.entriesInFile, denoptim.files.FileUtils.isLineInTxtFile(), denoptim.utils.SizeControlledSet.maxSize, denoptim.utils.SizeControlledSet.usingDisk, and denoptim.io.DenoptimIO.writeData().
Referenced by denoptim.ga.EvolutionaryAlgorithm.evolvePopulation(), denoptim.ga.EvolutionaryAlgorithm.processInitialPopCandidate(), and denoptim.utils.SizeControlledSetTest.test().
synchronized boolean denoptim.utils.SizeControlledSet.contains | ( | String | entry | ) | throws IOException |
Checks if an entry is contained in this collection.
entry | the entry to search for. |
true
if the entry is already present in the collection. IOException | when handling of the memory written on disk returns exception. |
Definition at line 152 of file SizeControlledSet.java.
References denoptim.utils.SizeControlledSet.data, denoptim.utils.SizeControlledSet.dataOnDisk, denoptim.files.FileUtils.isLineInTxtFile(), and denoptim.utils.SizeControlledSet.usingDisk.
Referenced by denoptim.utils.SizeControlledSetTest.test().
synchronized int denoptim.utils.SizeControlledSet.size | ( | ) |
Returns the number of unique entries.
Definition at line 173 of file SizeControlledSet.java.
References denoptim.utils.SizeControlledSet.data, and denoptim.utils.SizeControlledSet.entriesInFile.
Referenced by denoptim.utils.SizeControlledSetTest.test().
|
private |
The file used to store all entries on disk.
Definition at line 56 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry().
|
private |
The actual data collection.
Definition at line 71 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry(), denoptim.utils.SizeControlledSet.contains(), denoptim.utils.SizeControlledSet.size(), and denoptim.utils.SizeControlledSet.SizeControlledSet().
|
private |
The file used to deal with entries that do not fit in the maximum size of this set.
Definition at line 51 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry(), and denoptim.utils.SizeControlledSet.contains().
|
private |
Number of entries written to file.
Definition at line 66 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry(), and denoptim.utils.SizeControlledSet.size().
|
private |
Maximum size of the set.
If there is need to use more entries, the entries that do not fit are stored on disk.
Definition at line 45 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry(), and denoptim.utils.SizeControlledSet.SizeControlledSet().
|
private |
Flag signalling the use of the disk.
Definition at line 61 of file SizeControlledSet.java.
Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry(), and denoptim.utils.SizeControlledSet.contains().