Package dev.roanh.cpqindex
Class Index
java.lang.Object
dev.roanh.cpqindex.Index
Implementation of a graph database index based on k-path-bisimulation
and with support for indexing by CPQ cores. This index is inspired by the
path index proposed by Yuya Sasaki, George Fletcher and Makoto Onizuka.
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
Representation of a single block in the index containing the paths, labels and cores of the partition it represents. -
Field Summary
Modifier and TypeFieldDescriptionprivate List<Index.Block>
List of all blocks in the final layer of this index.private boolean
Whether CPQ cores should be or have been computed for this index.private final boolean
Boolean indicating whether explicit representations of cores and label sequences should be saved for the computed blocks.private Map<CanonForm.CoreHash,
List<Index.Block>> Map from CPQ core hash to the blocks this CPQ is present in.private final int
The value of k (the CPQ diameter) this index was computed for.private dev.roanh.gmark.util.RangeList<List<Index.Block>>
List of blocks in this index by layer (index 0 is k = 1, etc).private int
The maximum number of same layer CPQs allowed in a single intersection.private dev.roanh.gmark.util.RangeList<dev.roanh.gmark.core.graph.Predicate>
List of predicates (labels) that appear in this index by ID.private ProgressListener
Progress listener to inform of any computation updates. -
Constructor Summary
ConstructorDescriptionIndex
(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, boolean computeCores, boolean computeLabels, int threads) Constructs a new CPQ-native index for the given graph, diameter.Index
(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, boolean computeCores, boolean computeLabels, int threads, int maxIntersections, ProgressListener listener) Constructs a new CPQ-native index for the given graph, diameter.Index
(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, int threads) Constructs a new CPQ-native index for the given graph and diameter.Index
(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, int threads, int maxIntersections) Constructs a new CPQ-native index for the given graph, diameter and diameter limit.Index
(InputStream source) Reads a previously saved index. -
Method Summary
Modifier and TypeMethodDescriptionprivate final void
computeBlocks
(dev.roanh.gmark.util.RangeList<List<LabelledPath>> segments) After graph partitioning computes the index blocks.final void
computeCores
(int threads) Computes CPQ cores for each block in this index.final List<Index.Block>
Gets all the blocks in this index.final long
Gets the total number of cores in this index, this is the sum of all cores in each block.final int
Gets the total number of unique cores in this index, this is the number of unique index keys.private final void
Constructs the map from CPQ core has to the blocks this core occurs in.private final dev.roanh.gmark.util.RangeList<List<LabelledPath>>
Partitions all the paths in the given graph according to k-path-bisimulation.final void
print()
Prints the index to standard output.query
(dev.roanh.gmark.conjunct.cpq.CPQ cpq) Runs the given query on this index and returns the result.final void
setIntersections
(int intersections) Sets the maximum number of same level CPQ intersections allowed.final void
setProgressListener
(ProgressListener listener) Sets the progress listener to send computation updates to.final void
sort()
Sorts all the list of blocks of this index.private static final int
Compares the given paths based on their labels, cyclic properties, source and target.private static final int
Compares the given paths based on their segments, cyclic properties, source and target.final void
write
(OutputStream target, boolean full) Write this index to the given output stream.
-
Field Details
-
computeLabels
private final boolean computeLabelsBoolean indicating whether explicit representations of cores and label sequences should be saved for the computed blocks. Saving these will take significantly more memory and is only really relevant when printing the index withprint()
, callingIndex.Block.getCores()
or callingIndex.Block.getLabels()
. -
k
private final int kThe value of k (the CPQ diameter) this index was computed for. -
maxIntersections
private int maxIntersectionsThe maximum number of same layer CPQs allowed in a single intersection. -
computeCores
private boolean computeCoresWhether CPQ cores should be or have been computed for this index. -
predicates
private dev.roanh.gmark.util.RangeList<dev.roanh.gmark.core.graph.Predicate> predicatesList of predicates (labels) that appear in this index by ID. -
layers
List of blocks in this index by layer (index 0 is k = 1, etc). -
blocks
List of all blocks in the final layer of this index. This is the layer for k equal tok
. -
coreToBlock
Map from CPQ core hash to the blocks this CPQ is present in. -
progress
Progress listener to inform of any computation updates.
-
-
Constructor Details
-
Index
public Index(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, int threads) throws IllegalArgumentException, InterruptedExceptionConstructs a new CPQ-native index for the given graph and diameter.- Parameters:
g
- The graph to compute and index for.k
- The CPQ diameter k to compute the index for.threads
- The number of CPU threads to use for computing cores.- Throws:
IllegalArgumentException
- When k is less than 1.InterruptedException
- When the current thread is interrupted during core computation.
-
Index
public Index(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, int threads, int maxIntersections) throws IllegalArgumentException, InterruptedExceptionConstructs a new CPQ-native index for the given graph, diameter and diameter limit.- Parameters:
g
- The graph to compute and index for.k
- The CPQ diameter k to compute the index for.threads
- The number of CPU threads to use for computing cores.maxIntersections
- The maximum number of same level CPQs allowed in intersections. Limiting intersection CPQs greatly decreases the number of cores that need to be computed.- Throws:
IllegalArgumentException
- When k is less than 1.InterruptedException
- When the current thread is interrupted during core computation.
-
Index
public Index(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, boolean computeCores, boolean computeLabels, int threads) throws IllegalArgumentException, InterruptedExceptionConstructs a new CPQ-native index for the given graph, diameter.- Parameters:
g
- The graph to compute and index for.k
- The CPQ diameter k to compute the index for.computeCores
- True to compute cores, if false cores are not computed and can instead later be computed usingcomputeCores(int)
if desired.computeLabels
- True to compute core and label sequence labels for each index block.threads
- The number of CPU threads to use for computing cores.- Throws:
IllegalArgumentException
- When k is less than 1.InterruptedException
- When the current thread is interrupted during core computation.- See Also:
-
Index
public Index(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g, int k, boolean computeCores, boolean computeLabels, int threads, int maxIntersections, ProgressListener listener) throws IllegalArgumentException, InterruptedExceptionConstructs a new CPQ-native index for the given graph, diameter.- Parameters:
g
- The graph to compute and index for.k
- The CPQ diameter k to compute the index for.computeCores
- True to compute cores, if false cores are not computed and can instead later be computed usingcomputeCores(int)
if desired.computeLabels
- True to compute core and label sequence labels for each index block.threads
- The number of CPU threads to use for computing cores.maxIntersections
- The maximum number of same level CPQs allowed in intersections. Limiting intersection CPQs greatly decreases the number of cores that need to be computed.listener
- The progress listener to send computation progress updates to.- Throws:
IllegalArgumentException
- When k is less than 1.InterruptedException
- When the current thread is interrupted during core computation.- See Also:
-
Index
Reads a previously saved index. Any previously attached progress listeners will be detached.- Parameters:
source
- The input stream to read from.- Throws:
IOException
- When an IOException occurs.- See Also:
-
-
Method Details
-
setIntersections
Sets the maximum number of same level CPQ intersections allowed. Limiting intersection CPQs greatly decreases the number of cores that need to be computed. Note that this limit does not count intersection with identity.- Parameters:
intersections
- The maximum number of CPQs in an intersection.- Throws:
IllegalStateException
- When cores have already been computed for this index.
-
write
Write this index to the given output stream.- Parameters:
target
- The output stream to write to.full
- When true extra information is saved that is required for core computation.- Throws:
IOException
- When an IOException occurs.- See Also:
-
query
Runs the given query on this index and returns the result. Note that the intersection limit has to be respect if a limit was set.- Parameters:
cpq
- The query to run.- Returns:
- The paths matched by the query.
- Throws:
IllegalArgumentException
- When the query has a diameter that is larger than the diameter of this index.- See Also:
-
setIntersections(int)
CPQ.getDiameter()
-
setProgressListener
Sets the progress listener to send computation updates to.- Parameters:
listener
- The listener to send computation updates to.- See Also:
-
getBlocks
Gets all the blocks in this index.- Returns:
- All the blocks in this index.
-
sort
public final void sort()Sorts all the list of blocks of this index. There's is no real reason to do this other than to make the output ofprint()
more organised.- See Also:
-
print
public final void print()Prints the index to standard output.- See Also:
-
mapCoresToBlocks
private final void mapCoresToBlocks()Constructs the map from CPQ core has to the blocks this core occurs in. -
getTotalCores
public final long getTotalCores()Gets the total number of cores in this index, this is the sum of all cores in each block.- Returns:
- The total number of cores.
- See Also:
-
getUniqueCores
public final int getUniqueCores()Gets the total number of unique cores in this index, this is the number of unique index keys.- Returns:
- The total number of unique cores.
- See Also:
-
computeBlocks
After graph partitioning computes the index blocks.- Parameters:
segments
- The partitioned segments of the graph.- See Also:
-
computeCores
Computes CPQ cores for each block in this index. Note that if this index was saved and read back that it is only possible to compute cores if the index was fully saved with extra state information.- Parameters:
threads
- The number of CPU threads to use to compute cores.- Throws:
InterruptedException
- When the current thread is interrupted.IllegalStateException
- When cores have already been computed for this index of when this index is read back and was not fully saved.- See Also:
-
partition
private final dev.roanh.gmark.util.RangeList<List<LabelledPath>> partition(dev.roanh.gmark.util.UniqueGraph<Integer, dev.roanh.gmark.core.graph.Predicate> g) throws IllegalArgumentExceptionPartitions all the paths in the given graph according to k-path-bisimulation.- Parameters:
g
- The graph to partition.- Returns:
- The partitioned paths in the graph.
- Throws:
IllegalArgumentException
- When the diameter of this index k is less than 1.
-
sortPaths
Compares the given paths based on their segments, cyclic properties, source and target.- Parameters:
a
- The first path.b
- The second path.- Returns:
- A value less than 0 if
a < b
, a value equal to 0 ifa == b
and a value greater than 0 ifa > b
.
-
sortOnePath
Compares the given paths based on their labels, cyclic properties, source and target.- Parameters:
a
- The first path.b
- The second path.- Returns:
- A value less than 0 if
a < b
, a value equal to 0 ifa == b
and a value greater than 0 ifa > b
.
-