Skip to content

Commit

Permalink
apacheGH-1912: GraphMemFactory functions for GraphMem2
Browse files Browse the repository at this point in the history
  • Loading branch information
afs authored and cnanjo committed Mar 1, 2024
1 parent 926f9a4 commit 740a216
Showing 1 changed file with 84 additions and 8 deletions.
92 changes: 84 additions & 8 deletions jena-core/src/main/java/org/apache/jena/graph/GraphMemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,111 @@

package org.apache.jena.graph;

import java.util.Iterator;

import org.apache.jena.graph.impl.GraphBase ;
import org.apache.jena.mem.GraphMem ;
import org.apache.jena.mem2.GraphMem2Fast;
import org.apache.jena.mem2.GraphMem2Legacy;
import org.apache.jena.mem2.GraphMem2Roaring;
import org.apache.jena.util.iterator.ExtendedIterator ;
import org.apache.jena.util.iterator.NullIterator ;

/**
A factory class for creating memory Graphs.
*/
* A factory class for creating memory Graphs.
* <p>
* Apache Jena is migrating to term semantics graph for consistency across all in-memory and persistent storage graphs
*
*/

@SuppressWarnings("deprecation")
public class GraphMemFactory
{
private GraphMemFactory() {}

/**
Answer a memory-based Graph.
* Answer a memory-based graph.
* This is the system default.
*/
public static Graph createDefaultGraph()
{ return GraphMemFactory.createGraphMem( ); }

/**
* This function will track the preferred general purpose graph.
* It will switch from "same value" to "same term"
*/
@SuppressWarnings("deprecation")
public static Graph createGraphMem()
{ return new GraphMem(); }
{ return new org.apache.jena.mem.GraphMem(); }

/**
* Answer a memory-based graph with "same value" semantics
* used in Jena2, Jena3 and Jena4 for in-memory graphs.
* Jena5 may change to "same term" semantics.
* This method will continue to provide a "same value" graph.
*/
@SuppressWarnings("deprecation")
public static Graph createDefaultGraphSameValue()
{ return new org.apache.jena.mem.GraphMem(); }

/**
* Answer a memory-based graph with "same term" semantics
* This method will continue to provide the preferred general purpose "same term" graph.
*/
public static Graph createDefaultGraphSameTerm()
{ return createGraphMem2(); }

/**
* A graph that stores triples in memory. This class is not thread-safe.
* <p>
* <ul>
* <li>This graph provides term equality.</li>
* <li>Iterator over this graph does not provide Iterator.remove</li>
* </ul>
* <p>
* It has improved performance compared to {@link org.apache.jena.mem.GraphMem}
* with a simpler implementation, primarily due to not providing support for {@link Iterator#remove}.
* <p>
* See {@link GraphMem2Legacy} for details.
*/
public static Graph createGraphMem2Basic()
{ return new GraphMem2Legacy(); }

/**
* A graph that stores triples in memory. This class is not thread-safe.
* <p>
* <ul>
* <li>This graph provides term equality.</li>
* <li>Iterator over this graph does not provide Iterator.remove</li>
* </ul>
* <p>
* This graph implementation provides improved performance with a minor increase in memory usage.
* <p>
* See {@link GraphMem2Fast} for details.
*/
public static Graph createGraphMem2()
{ return new GraphMem2Fast(); }

/**
* A graph that stores triples in memory. This class is not thread-safe.
* <p>
* <ul>
* <li>This graph provides term equality.</li>
* <li>Iterator over this graph does not provide Iterator.remove</li>
* </ul>
* <p>
* {@link GraphMem2Roaring} is focused on handling large in-memory graphs.
* It uses <a href="https://roaringbitmap.org/">Roaring bitmaps</a> for indexing.
* <p>
* See {@link GraphMem2Roaring} for details.
*/
public static Graph createGraphMem2Roaring()
{ return new GraphMem2Roaring(); }

private final static Graph emptyGraph = new GraphBase() {
@Override
protected ExtendedIterator<Triple> graphBaseFind(Triple triplePattern) {
return NullIterator.instance() ;
return NullIterator.instance();
}
} ;
};

/** Immutable graph with no triples */
public static Graph empty() { return emptyGraph ; }
Expand Down

0 comments on commit 740a216

Please sign in to comment.