|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsim.field.SparseField
sim.field.grid.SparseGrid3D
A storage facility for sparse objects in discrete 3D space, using HashMaps. SparseGrid3D differs from ObjectGrid3D in several respects:
Generally speaking, if you have a grid of objects, one per location, you should use an ObjectGrid3D. If you have a large grid occupied by a few objects, or those objects can pile up on the same grid location, you should use a SparseGrid3D.
In either case, you might consider storing the location of an object IN THE OBJECT ITSELF if you need to query for the object location often -- it's faster than the hashtable lookup in SparseGrid3D, and certainly faster than searching the entire array of an ObjectGrid3D.
Nested Class Summary |
Nested classes inherited from class sim.field.SparseField |
SparseField.LocationAndIndex |
Field Summary | |
protected int |
height
|
protected int |
length
|
protected int |
width
|
Fields inherited from class sim.field.SparseField |
allObjects, INITIAL_BAG_SIZE, LARGE_BAG_RATIO, locationAndIndexHash, MIN_BAG_SIZE, objectHash, removeEmptyBags, replaceLargeBags, REPLACEMENT_BAG_RATIO |
Constructor Summary | |
SparseGrid3D(int width,
int height,
int length)
|
Method Summary | |
int |
getHeight()
Returns the height of the grid |
int |
getLength()
Returns the length of the grid |
Bag |
getNeighborsHamiltonianDistance(int x,
int y,
int z,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos,
IntBag zPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) + abs(z-Z) <= dist. |
void |
getNeighborsHamiltonianDistance(int x,
int y,
int z,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos,
IntBag zPos)
|
Bag |
getNeighborsMaxDistance(int x,
int y,
int z,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos,
IntBag zPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y), abs(z-Z) ) <= dist. |
void |
getNeighborsMaxDistance(int x,
int y,
int z,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos,
IntBag zPos)
|
Int3D |
getObjectLocation(java.lang.Object obj)
Returns the object location, or null if there is no such object. |
Double3D |
getObjectLocationAsDouble3D(java.lang.Object obj)
Returns the object location as a Double3D, or as null if there is no such object. |
Bag |
getObjectsAtLocation(int x,
int y,
int z)
Returns a bag containing all the objects at a given location -- which MIGHT be empty or MIGHT be null (which should also be interpreted as "empty") when there are no objects at the location. |
Bag |
getObjectsAtLocations(IntBag xPos,
IntBag yPos,
IntBag zPos,
Bag result)
For each |
int |
getWidth()
Returns the width of the grid |
int |
numObjectsAtLocation(int x,
int y,
int z)
Returns the number of objects stored in the grid at the given location. |
Bag |
removeObjectsAtLocation(int x,
int y,
int z)
Removes all the objects stored at the given location and returns them as a Bag (which you are free to modify). |
boolean |
setObjectLocation(java.lang.Object obj,
Int3D location)
Changes the location of an object, or adds if it doesn't exist yet. |
boolean |
setObjectLocation(java.lang.Object obj,
int x,
int y,
int z)
Changes the location of an object, or adds if it doesn't exist yet. |
int |
stx(int x)
|
int |
sty(int y)
|
int |
stz(int z)
|
int |
tx(int x)
|
int |
ty(int y)
|
int |
tz(int z)
|
Methods inherited from class sim.field.SparseField |
clear, exists, getAllObjects, getObjectIndex, getObjectsAtLocation, getObjectsAtLocationOfObject, getObjectsAtLocations, getRawObjectLocation, iterator, locationBagIterator, numObjectsAtLocation, numObjectsAtLocationOfObject, remove, removeObjectsAtLocation, setObjectLocation |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int width
protected int height
protected int length
Constructor Detail |
public SparseGrid3D(int width, int height, int length)
Method Detail |
public int getWidth()
public int getHeight()
public int getLength()
public final int tx(int x)
public final int ty(int y)
public final int tz(int z)
public int stx(int x)
public int sty(int y)
public int stz(int z)
public int numObjectsAtLocation(int x, int y, int z)
public Bag getObjectsAtLocation(int x, int y, int z)
public Double3D getObjectLocationAsDouble3D(java.lang.Object obj)
public Int3D getObjectLocation(java.lang.Object obj)
public Bag removeObjectsAtLocation(int x, int y, int z)
public boolean setObjectLocation(java.lang.Object obj, int x, int y, int z)
public boolean setObjectLocation(java.lang.Object obj, Int3D location)
public void getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos)
public void getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, IntBag xPos, IntBag yPos, IntBag zPos)
public Bag getNeighborsMaxDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
public Bag getNeighborsHamiltonianDistance(int x, int y, int z, int dist, boolean toroidal, Bag result, IntBag xPos, IntBag yPos, IntBag zPos)
public Bag getObjectsAtLocations(IntBag xPos, IntBag yPos, IntBag zPos, Bag result)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |