Class TimelyMemory<Timestamp extends Comparable<Timestamp>>
java.lang.Object
tools.refinery.interpreter.matchers.util.TimelyMemory<Timestamp>
- All Implemented Interfaces:
Clearable,Resumable<Timestamp>,UnmaskedResumable<Timestamp>
public class TimelyMemory<Timestamp extends Comparable<Timestamp>>
extends Object
implements Clearable, UnmaskedResumable<Timestamp>
A timely memory implementation that incrementally maintains the
Timelines of tuples. The memory is capable of
lazy folding (see Resumable).- Since:
- 2.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classprotected static final classprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Tuple, TreeMap<Timestamp, TimelyMemory.CumulativeCounter>> protected final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFoldingState(Tuple tuple, TimelyMemory.FoldingState state, Timestamp timestamp) Registers the given folding state for the specified timestamp and tuple.asMap()voidclear()Clear all partial matchings stored in memoryprotected TimelyMemory.SignChangecomputeDiffsEager(Direction direction, TimelyMemory.CumulativeCounter counter, TimelyMemory.SignChange signChangeAtPrevious, Timestamp timestamp, Diff<Timestamp> diffs) Utility method that computes the timeline diffs in case of eager memories.protected voidcomputeDiffsLazy(Direction direction, int oldCumulative, int newCumulative, Timestamp timestamp, Timestamp nextTimestamp, Diff<Timestamp> diffs) Utility method that computes the timeline diffs in case of lazy memories.booleancontainsKey(ITuple tuple) doFoldingStep(Tuple tuple, TimelyMemory.FoldingState state, Timestamp timestamp) protected voidgcCounters(TimelyMemory.CumulativeCounter counter, Tuple tuple, Timestamp timestamp) Garbage collects the counter of the given tuple and timestamp if the new diff is zero.intReturns the number of tuples that are present at the moment 'infinity'.protected TimelyMemory.CumulativeCountergetCounter(Tuple tuple, Timestamp timestamp) On-demand initializes and returns the counter for the given tuple and timestamp.Returns the smallest timestamp where lazy folding shall be resumed, or null if there is no more folding to do in this resumable.Returns the set of tuples for which lazy folding shall be resumed at the next timestamp.booleanisEmpty()booleanisPresentAtInfinity(Tuple tuple) Returns true if the given tuple is present at the moment 'infinity'.keySet()removeEager(Tuple tuple, Timestamp timestamp) removeLazy(Tuple tuple, Timestamp timestamp) When called, the folding of the state shall be resumed at the given timestamp.intsize()toString()protected voidupdateTimeline(Tuple tuple, Diff<Timestamp> diff) Updates and garbage collects the timeline of the given tuple based on the given timeline diff.
-
Field Details
-
counters
protected final Map<Tuple,TreeMap<Timestamp extends Comparable<Timestamp>, countersTimelyMemory.CumulativeCounter>> -
timelines
-
foldingState
public final TreeMap<Timestamp extends Comparable<Timestamp>,Map<Tuple, foldingStateTimelyMemory.FoldingState>> -
presentAtInfinity
-
isLazy
protected final boolean isLazy -
EMPTY_DIFF
-
-
Constructor Details
-
TimelyMemory
public TimelyMemory() -
TimelyMemory
public TimelyMemory(boolean isLazy)
-
-
Method Details
-
getResumableTuples
Description copied from interface:UnmaskedResumableReturns the set of tuples for which lazy folding shall be resumed at the next timestamp.- Specified by:
getResumableTuplesin interfaceUnmaskedResumable<Timestamp extends Comparable<Timestamp>>
-
getResumableTimestamp
Description copied from interface:ResumableReturns the smallest timestamp where lazy folding shall be resumed, or null if there is no more folding to do in this resumable.- Specified by:
getResumableTimestampin interfaceResumable<Timestamp extends Comparable<Timestamp>>
-
addFoldingState
Registers the given folding state for the specified timestamp and tuple. If there is already a state stored, the two states will be merged together. -
resumeAt
Description copied from interface:UnmaskedResumableWhen called, the folding of the state shall be resumed at the given timestamp. The resumable is expected to do a folding step at the given timestamp only. Afterwards, folding shall be interrupted, even if there is more folding to do towards higher timestamps.- Specified by:
resumeAtin interfaceUnmaskedResumable<Timestamp extends Comparable<Timestamp>>
-
doFoldingStep
protected Diff<Timestamp> doFoldingStep(Tuple tuple, TimelyMemory.FoldingState state, Timestamp timestamp) -
getCounter
On-demand initializes and returns the counter for the given tuple and timestamp. -
gcCounters
Garbage collects the counter of the given tuple and timestamp if the new diff is zero. -
computeDiffsLazy
protected void computeDiffsLazy(Direction direction, int oldCumulative, int newCumulative, Timestamp timestamp, Timestamp nextTimestamp, Diff<Timestamp> diffs) Utility method that computes the timeline diffs in case of lazy memories. The diffs will be inserted into the input parameter. This method computes diffs for entire plateaus that spans from timestamp to nextTimestamp. Compared to the eager version of this method, the lazy version makes use of both the old and the new cumulative values because it can happen that the cumulative is incremented by a value that is larger than 1 (as folding states are merged together). This means that we cant decide whether the cumulative became positive by comparing the new value to 1. -
computeDiffsEager
protected TimelyMemory.SignChange computeDiffsEager(Direction direction, TimelyMemory.CumulativeCounter counter, TimelyMemory.SignChange signChangeAtPrevious, Timestamp timestamp, Diff<Timestamp> diffs) Utility method that computes the timeline diffs in case of eager memories. The diffs will be inserted into the input parameter. This method computes diffs that describe momentary changes instead of plateaus. Returns aTimelyMemory.SignChangethat describes how the sign has changed at the given timestamp. -
put
-
remove
-
putEager
-
putLazy
-
removeEager
-
removeLazy
-
updateTimeline
Updates and garbage collects the timeline of the given tuple based on the given timeline diff. -
getTuplesAtInfinity
- Since:
- 2.8
-
getCountAtInfinity
public int getCountAtInfinity()Returns the number of tuples that are present at the moment 'infinity'. -
isPresentAtInfinity
Returns true if the given tuple is present at the moment 'infinity'. -
isEmpty
public boolean isEmpty() -
size
public int size() -
keySet
-
asMap
-
get
-
clear
public void clear()Description copied from interface:ClearableClear all partial matchings stored in memory -
containsKey
-
toString
-