-
Notifications
You must be signed in to change notification settings - Fork 2
PileSpace Class
Concrete implementation of a tuplespace datastructure. Represents a strongly typed set of tuples that can be access through pattern matching. Provides methods to query and manipulate the set. This class imposes lifo ordering on the underlying tuples.
Object > SpaceBase
public sealed class PileSpace : SpaceBase, ISpace
Name | Description |
---|---|
PileSpace(ITupleFactory) | Initializes a new instance of the PileSpace class. All tuples will be created using the provided tuple factory; if none is provided the default TupleFactory will be used. |
Name | Description |
---|---|
GetIndex(Int32) | Returns the last index contained within the space to force lifo ordering. |
Get(IPattern) | Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation will block if no elements match. |
Get(Object[]) | Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation will block if no elements match. |
GetP(IPattern) | Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match. |
GetP(Object[]) | Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match. |
GetAll(IPattern) | Retrieves and removes all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match. |
GetAll(Object[]) | Retrieves and removes all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match. |
Query(IPattern) | Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation will block if no elements match. |
Query(Object[]) | Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation will block if no elements match. |
QueryP(IPattern) | Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match. |
QueryP(Object[]) | Retrieves a clone of the first tuple from the Space, matching the specified pattern.The operation is non-blocking.The operation will return null if no elements match. |
QueryAll(IPattern) | Retrieves clones of all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match. |
QueryAll(Object[]) | Retrieves clones of all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match. |
Put(ITuple) | Inserts the tuple passed as argument into the Space. |
Put(Object[]) | Inserts the tuple passed as argument into the Space. |
The PileSpace class is a threadsafe data structure. It implements the ISpace interface.
You can add tuples to a Space by using the Put methods. Conversely, tuples can be fetched through Query, QueryP, QueryAll, Get, GetP and GetAll.
Please note that:
- All variants of the Get operations not only fetches the tuple(s), but also removes them from the space.
- All variants of the Query operations returns a clone of the tuple stored in the Space, and not a referenced tuple.
Performance Considerations
The PileSpace class utilizes an internal hashmap for partitioning. Upon insertion of a Tuple, the hashvalue of the tuple is computed by the tuple signature. The tuple is then placed in a partition matching the hashvalue. This means that for each unique tuple signature, a partition is created. Subsequently, the searching time is reduced to the partition size.
When fetching tuples, the underlying parition in the tuple space is searched linearly. The worstcase runtime is thus O(n) where n is number of elements in the partition.
The PileSpace class utilizes a Readers-Writer-locking mechanism. This means that the multiple concurrent Query operations is possible. Furthermore, because the underlying set is partitioned, multiple Get and Put are possible, as long they are performed on seperate partitions.
Tuples are retrieved by LIFO ordering with respect to the underlying partitions.
The following example shows how the ordering effect transactions when using a LIFO based space.
static void Main(string[] args)
{
ISpace lifoOrdered = new PileSpace();
Console.WriteLine("Putting and getting tuple's using LIFO ordering:");
for(int cnt=0; cnt<10; cnt++)
{
lifoOrdered.Put(cnt);
}
for (int cnt = 0; cnt < 10; cnt++)
{
ITuple tuple = lifoOrdered.Get(typeof(int));
Console.WriteLine(tuple);
}
Console.Read();
}
/*
The following is printed to the console:
Putting and getting tuple's using LIFO ordering:
<9>
<8>
<7>
<6>
<5>
<4>
<3>
<2>
<1>
<0>
*/