00001 package edu.tum.cs.util.datastruct; 00002 00003 public class Cache2D<TContext, TKey, TValue> extends Map2D<TContext, TKey, TValue> { 00004 public int numCacheHit = 0; 00005 public int numCacheMiss = 0; 00006 00007 public TValue get(TContext context, TKey key) { 00008 TValue value = super.get(context, key); 00009 if(value == null) 00010 numCacheMiss++; 00011 else 00012 numCacheHit++; 00013 return value; 00014 } 00015 00016 public float getHitRatio() { 00017 return (float)numCacheHit/getNumAccesses(); 00018 } 00019 00020 public int getNumAccesses() { 00021 return numCacheHit+numCacheMiss; 00022 } 00023 }