1 6 7 package com.hp.hpl.jena.graph; 8 9 18 public class TripleCache 19 { 20 26 public static int SIZE = 1000; 27 28 31 private Triple [] triples = new Triple[SIZE]; 32 33 37 public Triple put( Triple t ) 38 { triples[(t.hashCode() & 0x7fffffff) % SIZE] = t; return t; } 39 40 private static int count = 0; 41 private int id = ++count; 42 private int hits = 0; 43 private int misses = 0; 44 45 48 private int count() 49 { 50 int result = 0; 51 for (int i = 0; i < SIZE; i += 1) if (triples[i] != null) result += 1; 52 return result; 53 } 54 55 64 public Triple get( Node s, Node p, Node o ) 65 { 66 Triple already = triples[(Triple.hashCode( s, p, o ) & 0x7fffffff) % SIZE]; 67 return already == null || !already.sameAs( s, p, o ) ? null : already; 70 } 71 } 72 | Popular Tags |