com.hp.hpl.jena.graph
Class TripleCache

java.lang.Object
  extended by com.hp.hpl.jena.graph.TripleCache

public class TripleCache
extends Object

TripleCache caches triples according to their SPO members, to reduce store turnover at the expense of some added computation. The cache is implemented as an array indexed by the (reduced) hashCode of the triples it stores. Each slot is treated independantly and only the most recent stored triple is remembered - there is no weighting, LRU, or anything like that.

Author:
kers

Field Summary
static int SIZE
          The size of the cache array.
 
Constructor Summary
TripleCache()
           
 
Method Summary
 Triple get(Node s, Node p, Node o)
          Answer any triple in the cache with subject s, predicate p, and object o, or null if no such triple exists.
 Triple put(Triple t)
          Cache the triple t by storing it in the slot with the its reduced hash.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE

public static int SIZE
The size of the cache array. 1000 gets 80% hits when running the Jena test suite and all the slots get used. 10000 gets about 83% and *almost* all the slots get used. Absent real performance indicators, 1000 will do for now.

Constructor Detail

TripleCache

public TripleCache()
Method Detail

put

public Triple put(Triple t)
Cache the triple t by storing it in the slot with the its reduced hash. Any triple already in that slot vanishes. Answer that triple.


get

public Triple get(Node s,
                  Node p,
                  Node o)
Answer any triple in the cache with subject s, predicate p, and object o, or null if no such triple exists.

The implementation looks in the slot with the same reduced hashCode as the SPO combination would have. If the triple there has the same SPO, it is returned; otherwise null is returned.



Licenced under the Apache License, Version 2.0