|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsim.field.SparseField
sim.field.grid.SparseGrid2D
A storage facility for sparse objects in discrete 2D space, using HashMaps. SparseGrid2D differs from ObjectGrid2D in several respects:
Generally speaking, if you have a grid of objects, one per location, you should use an ObjectGrid2D. 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 SparseGrid2D.
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 SparseGrid2D, and certainly faster than searching the entire array of an ObjectGrid2D.
| Nested Class Summary |
| Nested classes inherited from class sim.field.SparseField |
SparseField.LocationAndIndex |
| Field Summary | |
protected int |
height
|
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 | |
SparseGrid2D(int width,
int height)
|
|
| Method Summary | |
int |
dlx(int x,
int y)
Hex downleft x. |
int |
dly(int x,
int y)
Hex downleft y. |
int |
downx(int x,
int y)
Hex down x. |
int |
downy(int x,
int y)
Hex down y. |
int |
drx(int x,
int y)
Hex downright x. |
int |
dry(int x,
int y)
Hex downright y. |
int |
getHeight()
Returns the height of the grid |
Bag |
getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist. |
void |
getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy abs(x-X) + abs(y-Y) <= dist. |
Bag |
getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. |
void |
getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Gets all neighbors located within the hexagon centered at (X,Y) and 2*dist+1 cells from point to opposite point inclusive. |
Bag |
getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist. |
void |
getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Gets all neighbors of a location that satisfy max( abs(x-X) , abs(y-Y) ) <= dist. |
Int2D |
getObjectLocation(java.lang.Object obj)
Returns the object location, or null if there is no such object. |
Double2D |
getObjectLocationAsDouble2D(java.lang.Object obj)
Returns the object location as a Double2D, or as null if there is no such object. |
Bag |
getObjectsAtLocation(int x,
int y)
Returns a bag containing all the objects at a given location, or null when there are no objects at the location. |
Bag |
getObjectsAtLocations(IntBag xPos,
IntBag yPos,
Bag result)
For each |
int |
getWidth()
Returns the width of the grid |
int |
numObjectsAtLocation(int x,
int y)
Returns the number of objects stored in the grid at the given location. |
Bag |
removeObjectsAtLocation(int x,
int y)
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,
Int2D 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)
Changes the location of an object, or adds if it doesn't exist yet. |
int |
stx(int x)
Simple [and fast] toroidal x. |
int |
sty(int y)
Simple [and fast] toroidal y. |
boolean |
trb(int x,
int y)
Horizontal edge is on the bottom for triangle. |
boolean |
trt(int x,
int y)
Horizontal edge is on the top for triangle. |
int |
tx(int x)
Toroidal x. |
int |
ty(int y)
Toroidal y. |
int |
ulx(int x,
int y)
Hex upleft x. |
int |
uly(int x,
int y)
Hex upleft y. |
int |
upx(int x,
int y)
Hex up x. |
int |
upy(int x,
int y)
Hex up y. |
int |
urx(int x,
int y)
Hex upright x. |
int |
ury(int x,
int y)
Hex upright y. |
| 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
| Constructor Detail |
public SparseGrid2D(int width,
int height)
| Method Detail |
public int getWidth()
getWidth in interface Grid2Dpublic int getHeight()
getHeight in interface Grid2Dpublic final int tx(int x)
Grid2D
tx in interface Grid2Dpublic final int ty(int y)
Grid2D
ty in interface Grid2Dpublic int stx(int x)
Grid2D
stx in interface Grid2Dpublic int sty(int y)
Grid2D
sty in interface Grid2D
public int ulx(int x,
int y)
Grid2D
ulx in interface Grid2D
public int uly(int x,
int y)
Grid2D
uly in interface Grid2D
public int urx(int x,
int y)
Grid2D
urx in interface Grid2D
public int ury(int x,
int y)
Grid2D
ury in interface Grid2D
public int dlx(int x,
int y)
Grid2D
dlx in interface Grid2D
public int dly(int x,
int y)
Grid2D
dly in interface Grid2D
public int drx(int x,
int y)
Grid2D
drx in interface Grid2D
public int dry(int x,
int y)
Grid2D
dry in interface Grid2D
public int upx(int x,
int y)
Grid2D
upx in interface Grid2D
public int upy(int x,
int y)
Grid2D
upy in interface Grid2D
public int downx(int x,
int y)
Grid2D
downx in interface Grid2D
public int downy(int x,
int y)
Grid2D
downy in interface Grid2D
public boolean trb(int x,
int y)
Grid2D
trb in interface Grid2D
public boolean trt(int x,
int y)
Grid2D
trt in interface Grid2D
public int numObjectsAtLocation(int x,
int y)
public Bag getObjectsAtLocation(int x,
int y)
public Double2D getObjectLocationAsDouble2D(java.lang.Object obj)
public Int2D getObjectLocation(java.lang.Object obj)
public Bag removeObjectsAtLocation(int x,
int y)
public boolean setObjectLocation(java.lang.Object obj,
int x,
int y)
public boolean setObjectLocation(java.lang.Object obj,
Int2D location)
public void getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Grid2D
getNeighborsMaxDistance in interface Grid2D
public void getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Grid2D
getNeighborsHamiltonianDistance in interface Grid2D
public void getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
IntBag xPos,
IntBag yPos)
Grid2D
getNeighborsHexagonalDistance in interface Grid2D
public Bag getNeighborsMaxDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
public Bag getNeighborsHamiltonianDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
public Bag getNeighborsHexagonalDistance(int x,
int y,
int dist,
boolean toroidal,
Bag result,
IntBag xPos,
IntBag yPos)
public Bag getObjectsAtLocations(IntBag xPos,
IntBag yPos,
Bag result)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||