Class MaskedTupleMemory<Timestamp extends Comparable<Timestamp>>
java.lang.Object
tools.refinery.interpreter.matchers.memories.MaskedTupleMemory<Timestamp>
- All Implemented Interfaces:
Clearable
,MaskedResumable<Timestamp>
,Resumable<Timestamp>
- Direct Known Subclasses:
DefaultMaskedTupleMemory
,IdentityMaskedTupleMemory
,NullaryMaskedTupleMemory
,TimelyDefaultMaskedTupleMemory
,TimelyIdentityMaskedTupleMemory
,TimelyNullaryMaskedTupleMemory
,TimelyUnaryMaskedTupleMemory
,UnaryMaskedTupleMemory
public abstract class MaskedTupleMemory<Timestamp extends Comparable<Timestamp>>
extends Object
implements Clearable, MaskedResumable<Timestamp>
Indexes a collection of tuples by their signature (i.e. footprint, projection) obtained according to a mask. May
belong to an "owner" (for documentation / traceability purposes).
There are timeless and timely versions of the different memories. Timely versions associate Timeline
s with
the stored tuples.
- Since:
- 2.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a tuple occurrence to the memory.boolean
Adds a tuple occurrence to the memory with the given signature.addWithTimestamp
(Tuple tuple, Timestamp timestamp) Adds a tuple occurrence to the memory with the given timestamp.addWithTimestamp
(Tuple tuple, Tuple signature, Timestamp timestamp) Adds a tuple occurrence to the memory with the given signature and timestamp.static <T extends Comparable<T>>
MaskedTupleMemory<T> create
(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner) Creates a new memory for the given owner that indexes tuples according to the given mask.static <T extends Comparable<T>>
MaskedTupleMemory<T> create
(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner, boolean isTimely) Creates a new memory for the given owner that indexes tuples according to the given mask.static <T extends Comparable<T>>
MaskedTupleMemory<T> create
(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner, boolean isTimely, boolean isLazy) Creates a new memory for the given owner that indexes tuples according to the given mask.abstract Collection
<Tuple> Retrieves tuples that have the specified signatureabstract int
getMask()
The mask according to which tuples are projected and indexed.getOrEmpty
(ITuple signature) Retrieves tuples that have the specified signature.getOrEmptyWithTimeline
(ITuple signature) Retrieves tuples with their associated timelines that have the specified signature.getOwner()
The node owning this memory.Returns the set of signatures for which lazy folding shall be resumed at the next timestamp.Returns the smallest timestamp where lazy folding shall be resumed, or null if there is no more folding to do in this resumable.Retrieves a read-only view of exactly those signatures for which at least one tuple is storedabstract int
getWithTimeline
(ITuple signature) Retrieves the tuples and their associated timelines that have the specified signature.void
initializeWith
(MaskedTupleMemory<Timestamp> other, Timestamp defaultValue) Initializes the contents of this memory based on the contents of another memory.boolean
isPresentAtInfinity
(ITuple signature) Returns true if there is any tuple with the given signature that is present at the timestamp +inf, false otherwise.boolean
isTimely()
Returns true of this memory is timely, false otherwise.iterator()
Iterates over distinct tuples stored in the memory, regardless of their signatures.protected IllegalStateException
raiseDuplicateDeletion
(Tuple tuple) protected IllegalStateException
raiseDuplicateInsertion
(Tuple tuple) boolean
Removes a tuple occurrence from the memory.boolean
Removes a tuple occurrence from the memory with the given signature.removeWithTimestamp
(Tuple tuple, Timestamp timestamp) Removes a tuple occurrence from the memory with the given timestamp.removeWithTimestamp
(Tuple tuple, Tuple signature, Timestamp timestamp) Removes a tuple occurrence from the memory with the given signature and timestamp.When called, the folding of the state shall be resumed at the given timestamp.toString()
-
Field Details
-
mask
The mask by which the tuples are indexed. -
owner
The object "owning" this memory. May be null.- Since:
- 1.7
-
-
Constructor Details
-
MaskedTupleMemory
-
-
Method Details
-
create
public static <T extends Comparable<T>> MaskedTupleMemory<T> create(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner) Creates a new memory for the given owner that indexes tuples according to the given mask. -
create
public static <T extends Comparable<T>> MaskedTupleMemory<T> create(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner, boolean isTimely) Creates a new memory for the given owner that indexes tuples according to the given mask. Clients can specify if the created memory should be timely or not.
Timely means that tuples are associated with a timeline.- Since:
- 2.3
-
create
public static <T extends Comparable<T>> MaskedTupleMemory<T> create(TupleMask mask, CollectionsFactory.MemoryType bucketType, Object owner, boolean isTimely, boolean isLazy) Creates a new memory for the given owner that indexes tuples according to the given mask. Clients can specify if the created memory should be timely or not. In case of timely memory, clients can also specify if the memory is lazy or not.
Timely means that tuples are associated with a timeline.
Lazyness can only be used together with timely memories. It means that the maintenance of the timelines is lazy, that is, the memory only updates its internal data structures at the timestamp affected by an update, and can be instructed later to resume the maintenance at higher timestamps, as well.- Since:
- 2.4
-
resumeAt
Description copied from interface:MaskedResumable
When 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:
resumeAt
in interfaceMaskedResumable<Timestamp extends Comparable<Timestamp>>
-
getResumableSignatures
Description copied from interface:MaskedResumable
Returns the set of signatures for which lazy folding shall be resumed at the next timestamp.- Specified by:
getResumableSignatures
in interfaceMaskedResumable<Timestamp extends Comparable<Timestamp>>
-
getResumableTimestamp
Description copied from interface:Resumable
Returns the smallest timestamp where lazy folding shall be resumed, or null if there is no more folding to do in this resumable.- Specified by:
getResumableTimestamp
in interfaceResumable<Timestamp extends Comparable<Timestamp>>
-
initializeWith
Initializes the contents of this memory based on the contents of another memory. The default value is associated with each tuple in the timely memories.- Since:
- 2.3
-
isPresentAtInfinity
Returns true if there is any tuple with the given signature that is present at the timestamp +inf, false otherwise.- Since:
- 2.4
-
isTimely
public boolean isTimely()Returns true of this memory is timely, false otherwise.- Since:
- 2.3
-
getOwner
The node owning this memory. May be null.- Since:
- 2.0
-
getMask
The mask according to which tuples are projected and indexed.- Since:
- 2.0
-
getKeysetSize
public abstract int getKeysetSize()- Returns:
- the number of distinct signatures of all stored tuples.
-
getTotalSize
public abstract int getTotalSize()- Returns:
- the total number of distinct tuples stored. Multiple copies of the same tuple, if allowed, are counted as
one.
This is currently not cached but computed on demand. It is therefore not efficient, and shall only be used for debug / profiling purposes.
-
iterator
Iterates over distinct tuples stored in the memory, regardless of their signatures. -
getSignatures
Retrieves a read-only view of exactly those signatures for which at least one tuple is stored- Since:
- 2.0
-
get
Retrieves tuples that have the specified signature- Returns:
- collection of tuples found, null if none
-
getWithTimeline
Retrieves the tuples and their associated timelines that have the specified signature.- Returns:
- the mappings from tuples to timelines, null if there is no mapping for the signature
- Since:
- 2.4
-
getOrEmpty
Retrieves tuples that have the specified signature.- Returns:
- collection of tuples found, never null
- Since:
- 2.1
-
getOrEmptyWithTimeline
Retrieves tuples with their associated timelines that have the specified signature.- Returns:
- map of tuples and timelines found, never null
- Since:
- 2.4
-
remove
Removes a tuple occurrence from the memory with the given signature.- Parameters:
tuple
- the tuple to be removed from the memorysignature
- precomputed footprint of the tuple according to the mask- Returns:
- true if this was the the last occurrence of the signature (according to the mask)
-
removeWithTimestamp
Removes a tuple occurrence from the memory with the given signature and timestamp.- Parameters:
tuple
- the tuple to be removed from the memorysignature
- precomputed footprint of the tuple according to the masktimestamp
- the timestamp associated with the tuple- Returns:
- A
Diff
describing how the timeline of the given tuple changed. - Since:
- 2.4
-
remove
Removes a tuple occurrence from the memory.- Parameters:
tuple
- the tuple to be removed from the memory- Returns:
- true if this was the the last occurrence of the signature (according to the mask)
-
removeWithTimestamp
Removes a tuple occurrence from the memory with the given timestamp.- Parameters:
tuple
- the tuple to be removed from the memorytimestamp
- the timestamp associated with the tuple- Returns:
- A
Diff
describing how the timeline of the given tuple changed. - Since:
- 2.4
-
add
Adds a tuple occurrence to the memory with the given signature.- Parameters:
tuple
- the tuple to be added to the memorysignature
- precomputed footprint of the tuple according to the mask- Returns:
- true if new signature encountered (according to the mask)
-
addWithTimestamp
Adds a tuple occurrence to the memory with the given signature and timestamp.- Parameters:
tuple
- the tuple to be added to the memorysignature
- precomputed footprint of the tuple according to the masktimestamp
- the timestamp associated with the tuple- Returns:
- A
Diff
describing how the timeline of the given tuple changed. - Since:
- 2.4
-
add
Adds a tuple occurrence to the memory.- Parameters:
tuple
- the tuple to be added to the memory- Returns:
- true if new signature encountered (according to the mask)
-
addWithTimestamp
Adds a tuple occurrence to the memory with the given timestamp.- Parameters:
tuple
- the tuple to be added to the memorytimestamp
- the timestamp associated with the tuple- Returns:
- A
Diff
describing how the timeline of the given tuple changed. - Since:
- 2.4
-
raiseDuplicateInsertion
-
raiseDuplicateDeletion
-
toString
-