step.encoding
Class CacheStrategy
java.lang.Object
|
+--step.encoding.Encoder
|
+--step.encoding.Strategy
|
+--step.encoding.RegularValueStrategy
|
+--step.encoding.CacheStrategy
- Direct Known Subclasses:
- PCacheStrategy
- public class CacheStrategy
- extends RegularValueStrategy
Use a simple caching strategy to replace values with a reference to a cache
slot. When a miss occurs, the strategy just replaces the next slot (on a
rotational basis) with the new value.
It is possible to chain cache strategies to get a multi-level exclusive cache
hierarchy.
NOTE: If the cache has a lot of misses, it will likely have a negative effect
on overall reduction; introducing lots of meta-data and artificial randomness
(as values get mapped to different slots).
Constructor Summary |
CacheStrategy(Encoder baseEncoder,
int cacheSize)
Create a new "cache" strategy. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
STRATEGY_NAME
public static final String STRATEGY_NAME
- See Also:
- Constant Field Values
_cache
protected StepObject[] _cache
_slots
protected StepInt[] _slots
_valueToSlot
protected Map _valueToSlot
CacheStrategy
public CacheStrategy(Encoder baseEncoder,
int cacheSize)
- Create a new "cache" strategy.
- Parameters:
baseEncoder
- the encoder to use for cache misses.cacheSize
- the number of elements to keep in the cache.
encode
public void encode(StepObject o,
EncodeContext context)
throws EncoderException,
IOException
- Encode a value using its cache slot ID.
- Specified by:
encode
in class Encoder
- Throws:
IOException
- if the encode operation encountered an I/O failure.
EncoderException
- if the encode operation encountered an error.
decode
public StepObject decode(DecodeContext context)
throws EncoderException,
IOException
- Decode a value using its cache slot ID.
- Specified by:
decode
in class Encoder
- Throws:
IOException
- if the decode operation encountered an I/O failure.
EncoderException
- if the decode operation encountered an error.
nextSlot
protected StepInt nextSlot()
- Rotate to the next cache slot.
dump
public void dump(int level)
- Specified by:
dump
in class Encoder