$darkmode
DENOPTIM
denoptim.utils.SizeControlledSet Class Reference

Class meant to collect unique strings without leading to memory overflow. More...

Collaboration diagram for denoptim.utils.SizeControlledSet:
[legend]

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SizeControlledSet()

denoptim.utils.SizeControlledSet.SizeControlledSet ( int  maxSize,
String  memoryFile,
String  allUIDsFile 
)

Constructor for a size-controlled storage of unique Strings.

Parameters
maxSizethe maximum size of entries to keep in the memory.
memoryFilethe pathname to a non-existing file that might be used to store entries on disk in case the maximum size is not sufficient.
allUIDsFilethe 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.

Member Function Documentation

◆ addNewUniqueEntry()

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.

Parameters
entrythe entry to search for and, possibly, to add to the set.
Returns
true if the set did not already contain the entry, which was then added.
Exceptions
IOExceptionwhen 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains()

synchronized boolean denoptim.utils.SizeControlledSet.contains ( String  entry) throws IOException

Checks if an entry is contained in this collection.

Parameters
entrythe entry to search for.
Returns
true if the entry is already present in the collection.
Exceptions
IOExceptionwhen 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

synchronized int denoptim.utils.SizeControlledSet.size ( )

Returns the number of unique entries.

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().

Here is the caller graph for this function:

Member Data Documentation

◆ allData

File denoptim.utils.SizeControlledSet.allData
private

The file used to store all entries on disk.

Definition at line 56 of file SizeControlledSet.java.

Referenced by denoptim.utils.SizeControlledSet.addNewUniqueEntry().

◆ data

Set<String> denoptim.utils.SizeControlledSet.data
private

◆ dataOnDisk

File denoptim.utils.SizeControlledSet.dataOnDisk
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().

◆ entriesInFile

int denoptim.utils.SizeControlledSet.entriesInFile = 0
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().

◆ maxSize

int denoptim.utils.SizeControlledSet.maxSize
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().

◆ usingDisk

boolean denoptim.utils.SizeControlledSet.usingDisk = false
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().


The documentation for this class was generated from the following file: