public class SimpleSpaceBase<T> extends Object
A wrapper around a SpaceBase
instance providing a simple, non-visitor based API, for applications making a basic CRUD use of SpaceBase.
Modifier and Type | Class and Description |
---|---|
static class |
SimpleSpaceBase.ExecutionMode |
Constructor and Description |
---|
SimpleSpaceBase(SpaceBase<T> base)
Creates a new SimpleSpaceBase instance wrapping an existing
SpaceBase |
SimpleSpaceBase(String name,
int dims,
SimpleSpaceBase.ExecutionMode mode,
int parallelism)
Creates a new SimpleSpaceBase.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(SpatialToken token)
Checks if the spatial element represented by a
SpatialToken currently exists in the data-store. |
void |
delete(SpatialToken token)
Deletes an element from the data store.
|
SpatialToken |
find(T elem,
AABB aabb)
Finds an element’s token that can be used for update and delete.
|
ElementAndBounds<T> |
getElement(SpatialToken token)
Returns the spatial element represented by a
SpatialToken . |
String |
getName()
Returns the SpaceBase store’s name.
|
SpaceBase<T> |
getSpaceBase()
Returns the wrapped
SpaceBase instance. |
SpatialToken |
insert(T elem,
AABB aabb)
Inserts an element to the data store.
|
<T2> Collection<co.paralleluniverse.common.util.Pair<T,T2>> |
join(SimpleSpaceBase<T2> other,
SpatialJoinQuery<? super T,? super T2> joinQuery)
Performs a spatial join on the store and another store, and visits every pair of elements - an element from each store - matching it one at a time.
|
Collection<co.paralleluniverse.common.util.Pair<T,T>> |
join(SpatialJoinQuery<? super T,? super T> joinQuery)
Performs a spatial join on the store, and visits every pair of elements matching it one at a time.
|
<T2> Collection<co.paralleluniverse.common.util.Pair<T,T2>> |
join(SpatialQuery<Object> region,
SimpleSpaceBase<T2> other,
SpatialJoinQuery<? super T,? super T2> joinQuery)
Performs a spatial join on a region of the store and another store, and visits every pair of elements - an element from each store - matching it one at a time.
|
Collection<co.paralleluniverse.common.util.Pair<T,T>> |
join(SpatialQuery<Object> region,
SpatialJoinQuery<? super T,? super T> joinQuery)
Performs a spatial join on a region of the store, and visits every pair of elements matching it one at a time.
|
Collection<T> |
query(SpatialQuery<? super T> query)
Performs a query on the store and visits all of the elements matching it, one at a time, for a read-only operation.
|
int |
size()
Returns the number of elements currently in the store.
|
void |
update(SpatialToken token,
AABB newAABB)
Updates the data store with a new bounding-box for an element which has already been inserted into the store.
|
public SimpleSpaceBase(String name, int dims, SimpleSpaceBase.ExecutionMode mode, int parallelism)
Creates a new SimpleSpaceBase.
name
- database namedims
- 2 for 2D, 3 for 3D etc…mode
- ExecutorMode.CONCURRENT
will run the user tasks in the user context. Only cleanup tasks will run in the background.ExecutorMode.PARALLEL
will run all the tasks in parallel.parallelism
- The number of threads to use for background tasks.public SpaceBase<T> getSpaceBase()
Returns the wrapped SpaceBase
instance.
public boolean contains(SpatialToken token)
Checks if the spatial element represented by a SpatialToken
currently exists in the data-store.
token
- The token representing the element.true
if the element represented by the token exists in the store, false
otherwise.public SpatialToken insert(T elem, AABB aabb)
Inserts an element to the data store.
In the current implementation, this method runs in O(log n)
time.
The aabb argument is copied by SpaceBase, so it may be modified by the user after passing it to this method.
elem
- The element to be inserted.aabb
- The element’s bounding-box.IllegalStateException
- If called from within a visitor.public int size()
Returns the number of elements currently in the store. This method runs in O(n)
time.
public void update(SpatialToken token, AABB newAABB)
Updates the data store with a new bounding-box for an element which has already been inserted into the store. The bounding-box may shrink, expand or move arbitrarily, but must remain valid. If the element represented by the token no longer exists in the data-store, this call is ignored and returns normally.
If the token has been obtained from another SpaceBase instance, this method may result in unexpected behavior.
In the current implementation, this method runs in O(1)
time in most cases, and in worst-case O(log n)
time.
The aabb argument is copied by SpaceBase, so it may be modified by the user after passing it to this method.
newAABB
- The element’s new bounding-box.token
- The token representing the element, which MUST have been obtained from this SpaceBase instance.IllegalArgumentException
- if the token or bounds are null, or if the bounds are invalid.IllegalStateException
- If called from within a visitor.public void delete(SpatialToken token)
Deletes an element from the data store. The element is represented by a token. If the element represented by the token no longer exists in the data-store, this call is ignored and returns normally.
If the token has been obtained from another SpaceBase instance, this method may result in unexpected behavior.
In the current implementation, this method runs in O(1)
time in most cases, and in worst-case O(log n)
time.
token
- The token representing the element, which MUST have been obtained from this SpaceBase instance.IllegalStateException
- If called from within a visitor.public String getName()
Returns the SpaceBase store’s name.
public ElementAndBounds<T> getElement(SpatialToken token)
Returns the spatial element represented by a SpatialToken
. If the element no longer exists in the data-store, this method returns null
token
- The token representing the element.null
if the element no longer exists in the data-store.public SpatialToken find(T elem, AABB aabb)
Finds an element’s token that can be used for update and delete. If the element does not exist in the store, or if it was not found within its bounding-box, this method will return a SpatialToken
that, when passed to contains()
will yield false
.
The aabb argument is copied by SpaceBase, so it may be modified by the user after passing it to this method.
elem
- The element.aabb
- The element’s bounding-box.null
if the element does not exist in the store, or if it was not found within its bounding-box.IllegalStateException
- If called from within a visitor.public Collection<T> query(SpatialQuery<? super T> query)
Performs a query on the store and visits all of the elements matching it, one at a time, for a read-only operation.
query
- The spatial query to perform.collection
of all elements matching the query.public Collection<co.paralleluniverse.common.util.Pair<T,T>> join(SpatialJoinQuery<? super T,? super T> joinQuery)
Performs a spatial join on the store, and visits every pair of elements matching it one at a time.
joinQuery
- The spatial join to perform.public Collection<co.paralleluniverse.common.util.Pair<T,T>> join(SpatialQuery<Object> region, SpatialJoinQuery<? super T,? super T> joinQuery)
Performs a spatial join on a region of the store, and visits every pair of elements matching it one at a time.
region
- A SpatialQuery
defining the region in which to perform the spatial join. Only elements matching this query will be considered in the join.joinQuery
- The spatial join to perform.collection
of all pairs of elements satisfying the join query.public <T2> Collection<co.paralleluniverse.common.util.Pair<T,T2>> join(SimpleSpaceBase<T2> other, SpatialJoinQuery<? super T,? super T2> joinQuery)
Performs a spatial join on the store and another store, and visits every pair of elements - an element from each store - matching it one at a time. The first element in each joined pair is a member of this
SpaceBase instance, while the second is a member of the instance passed as the other
parameter.
other
- The second SpaceBase instance to be used in the join. The second element in each joined pair will come from other
joinQuery
- The spatial join to perform.collection
of all pairs of elements satisfying the join query.public <T2> Collection<co.paralleluniverse.common.util.Pair<T,T2>> join(SpatialQuery<Object> region, SimpleSpaceBase<T2> other, SpatialJoinQuery<? super T,? super T2> joinQuery)
Performs a spatial join on a region of the store and another store, and visits every pair of elements - an element from each store - matching it one at a time. The first element in each joined pair is a member of this
SpaceBase instance, while the second is a member of the instance passed as the other
parameter.
other
- The second SpaceBase instance to be used in the join. The second element in each joined pair will come from other
region
- A SpatialQuery
defining the region (of both stores) in which to perform the spatial join. Only elements, in either store, matching this query will be considered in the join.joinQuery
- The spatial join to perform.collection
of all pairs of elements satisfying the join query.