- All Implemented Interfaces:
org.apache.jena.atlas.lib.Copyable<TripleStore>
,TripleStore
Inner structure:
- three FastHashMap
, one for each node (subject, predicate, object) in the triple
- each map maps from a node to a FastTripleBunch
- for up to 16 triples with the same subject, the bunch is an FastArrayBunch
, otherwise it is
a FastHashedTripleBunch
- for up to 32 triples with the same predicate and object, the bunch is an FastArrayBunch
, otherwise it is
a FastHashedTripleBunch
Other optimizations:
- each triple is added to three FastTripleBunch
es. To avoid the overhead of calculating the hash code three
times, the hash code is calculated once and passed to the FastTripleBunch
es.
- the different sizes for the FastArrayBunch
es are chosen:
- to avoid the memory-overhead of FastHashedTripleBunch
for a small number of triples
- the subject bunch is smaller than the predicate and object bunches, because the subject is typically used for
#contains operations, which are faster for FastHashedTripleBunch
es.
- the predicate and object bunches are the same size, because they are typically used for #find operations, which
typically do not answer #contains operations. Making them much larger might slow down #remove operations on the
graph.
- "ANY_PRE_OBJ" matches primarily use the object bunch unless the size of the bunch is larger than 400 triples. In
that case, there is a secondary lookup in the predicate bunch. Then the smaller bunch is used for the lookup.
Especially for RDF graphs there are some very common object nodes like "true"/"false" or "0"/"1". In that case,
a secondary lookup in the predicate bunch might be faster than a primary lookup in the object bunch.
- FastTripleStore#contains uses FastTripleBunch.anyMatchRandomOrder(java.util.function.Predicate<org.apache.jena.graph.Triple>)
for
"ANY_PRE_OBJ" lookups. This is only faster than JenaMapSetCommon.anyMatch(java.util.function.Predicate<E>)
if there are many matches and the set is ordered in an unfavorable way. "ANY_PRE_OBJ" matches usually fall into
this category. This optimization was only needed because the FastTripleBunch
es does not use the random
order of the triples in #anyMatch but the ordered dense array of triples, which is faster if there are only a few
matches.
- for the FastArrayBunches, the equals method of the triple is not called. Instead, only the two nodes that are
not part of the key of the containing map are compared.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a triple to the map.void
clear()
Remove all triples from the map.boolean
Answer true if the graph contains any triple matchingt
.copy()
Return a new triple store that is a copy of this one.int
Return the number of triples in the map.Returns anExtendedIterator
of all triples in the graph matching the given triple match.boolean
isEmpty()
Return true if the map is empty.void
Remove a triple from the map.stream()
Returns aStream
of all triples in the graph.Returns aStream
of Triples matching the given pattern.
-
Constructor Details
-
FastTripleStore
public FastTripleStore()
-
-
Method Details
-
add
Description copied from interface:TripleStore
Add a triple to the map.- Specified by:
add
in interfaceTripleStore
- Parameters:
triple
- to add
-
remove
Description copied from interface:TripleStore
Remove a triple from the map.- Specified by:
remove
in interfaceTripleStore
- Parameters:
triple
- to remove
-
clear
public void clear()Description copied from interface:TripleStore
Remove all triples from the map.- Specified by:
clear
in interfaceTripleStore
-
countTriples
public int countTriples()Description copied from interface:TripleStore
Return the number of triples in the map.- Specified by:
countTriples
in interfaceTripleStore
-
isEmpty
public boolean isEmpty()Description copied from interface:TripleStore
Return true if the map is empty.- Specified by:
isEmpty
in interfaceTripleStore
-
contains
Description copied from interface:TripleStore
Answer true if the graph contains any triple matchingt
.- Specified by:
contains
in interfaceTripleStore
- Parameters:
tripleMatch
- triple match pattern, which may be contained
-
stream
Description copied from interface:TripleStore
Returns aStream
of all triples in the graph. Note:BaseStream.parallel()
is supported.- Specified by:
stream
in interfaceTripleStore
- Returns:
- a stream of triples in this graph.
-
stream
Description copied from interface:TripleStore
Returns aStream
of Triples matching the given pattern. Note:BaseStream.parallel()
is supported.- Specified by:
stream
in interfaceTripleStore
- Parameters:
tripleMatch
- triple match pattern- Returns:
- a stream of triples in this graph matching the pattern.
-
find
Description copied from interface:TripleStore
Returns anExtendedIterator
of all triples in the graph matching the given triple match.- Specified by:
find
in interfaceTripleStore
-
copy
Description copied from interface:TripleStore
Return a new triple store that is a copy of this one. Since Nodes and Triples are immutable and shared, the copy can share the same Nodes and Triples.- Specified by:
copy
in interfaceorg.apache.jena.atlas.lib.Copyable<TripleStore>
- Specified by:
copy
in interfaceTripleStore
- Returns:
- an independent copy of this store
-