Class CoordSet
java.lang.Object
com.github.tommyettinger.ds.ObjectSet<Coord>
com.github.yellowstonegames.grid.CoordSet
- All Implemented Interfaces:
com.github.tommyettinger.ds.EnhancedCollection<Coord>, com.github.yellowstonegames.core.ISerializersNeeded, Iterable<Coord>, Collection<Coord>, Set<Coord>
public class CoordSet
extends com.github.tommyettinger.ds.ObjectSet<Coord>
implements com.github.yellowstonegames.core.ISerializersNeeded
A variant on jdkgdxds'
If no initialCapacity is supplied, or if this must resize to enter a Coord, this will use a capacity at least as large as the Coord cache, as defined by
This tends to perform significantly better with a high low factor, such as 0.9f, instead of a lower one like 0.5f . It also performs its best when the initial capacity is sufficient to hold every item this needs without resizing, but it typically only has to resize once if it has to resize at all.
ObjectSet class that only holds Coord items, and can do so more efficiently.
This assumes all Coord keys are in the Coord pool; that is, Coord.expandPoolTo(int, int) has been called with
the maximum values for Coord x and y. If you cannot be sure that the Coord pool will hold items placed into here, you
should use a normal ObjectSet instead, since some optimizations here require Coord items to be in the pool.
If no initialCapacity is supplied, or if this must resize to enter a Coord, this will use a capacity at least as large as the Coord cache, as defined by
Coord.getCacheWidth() by Coord.getCacheHeight(). While this
means that any resizing will potentially make this use much more memory, it avoids a situation where some dense key
sets could take hundreds of times longer than they should. It also usually doesn't use drastically more memory unless
the Coord pool has been expanded quite a bit. If the Coord pool hasn't been expanded, each set should use about 1MB
of memory or less when created with the default constructor.
This tends to perform significantly better with a high low factor, such as 0.9f, instead of a lower one like 0.5f . It also performs its best when the initial capacity is sufficient to hold every item this needs without resizing, but it typically only has to resize once if it has to resize at all.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.github.tommyettinger.ds.ObjectSet
com.github.tommyettinger.ds.ObjectSet.ObjectSetIterator<T> -
Field Summary
Fields inherited from class com.github.tommyettinger.ds.ObjectSet
keyTable, loadFactor, mask, shift, size, threshold -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected intprotected voidresize(int newSize) static CoordSetwith()Constructs an empty set given the type as a generic type argument.static CoordSetCreates a new CoordSet that holds only the given item, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetCreates a new CoordSet that holds only the given items, but can be resized.static CoordSetwith(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6, Coord item7) Creates a new CoordSet that holds only the given items, but can be resized.Methods inherited from class com.github.tommyettinger.ds.ObjectSet
add, addAll, addAll, addAll, addAll, addResize, appendTo, clear, clear, contains, containsAll, containsAll, containsAll, containsAny, containsAny, containsAnyIterable, ensureCapacity, equals, first, get, getHashMultiplier, getLoadFactor, getTableSize, hashCode, isEmpty, iterator, locateKey, notEmpty, parse, parse, parse, remove, removeAll, removeAll, removeAll, retainAll, setHashMultiplier, setLoadFactor, shrink, size, toArray, toArray, toString, truncate, with, with, with, with, with, with, with, with, withMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface com.github.tommyettinger.ds.EnhancedCollection
add, add, add, addAll, addAllIterable, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAllIterable, containsAny, removeAll, removeAllIterable, removeEach, removeEach, removeEach, removeEachIterable, toString, toString, toStringMethods inherited from interface Set
spliterator
-
Constructor Details
-
CoordSet
public CoordSet() -
CoordSet
public CoordSet(int initialCapacity) -
CoordSet
public CoordSet(int initialCapacity, float loadFactor) -
CoordSet
-
CoordSet
-
CoordSet
-
CoordSet
-
-
Method Details
-
place
-
equate
-
resize
protected void resize(int newSize) - Overrides:
resizein classcom.github.tommyettinger.ds.ObjectSet<Coord>
-
with
Constructs an empty set given the type as a generic type argument. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new set containing nothing
-
with
-
with
-
with
-
with
Creates a new CoordSet that holds only the given items, but can be resized.- Parameters:
item0- a Coord itemitem1- a Coord itemitem2- a Coord itemitem3- a Coord item- Returns:
- a new CoordSet that holds the given items
-
with
Creates a new CoordSet that holds only the given items, but can be resized.- Parameters:
item0- a Coord itemitem1- a Coord itemitem2- a Coord itemitem3- a Coord itemitem4- a Coord item- Returns:
- a new CoordSet that holds the given items
-
with
public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5) Creates a new CoordSet that holds only the given items, but can be resized.- Parameters:
item0- a Coord itemitem1- a Coord itemitem2- a Coord itemitem3- a Coord itemitem4- a Coord itemitem5- a Coord item- Returns:
- a new CoordSet that holds the given items
-
with
public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6) Creates a new CoordSet that holds only the given items, but can be resized.- Parameters:
item0- a Coord itemitem1- a Coord itemitem2- a Coord itemitem3- a Coord itemitem4- a Coord itemitem5- a Coord itemitem6- a Coord item- Returns:
- a new CoordSet that holds the given items
-
with
public static CoordSet with(Coord item0, Coord item1, Coord item2, Coord item3, Coord item4, Coord item5, Coord item6, Coord item7) Creates a new CoordSet that holds only the given items, but can be resized.- Parameters:
item0- a Coord itemitem1- a Coord itemitem2- a Coord itemitem3- a Coord itemitem4- a Coord itemitem5- a Coord itemitem6- a Coord item- Returns:
- a new CoordSet that holds the given items
-
with
Creates a new CoordSet that holds only the given items, but can be resized. This overload will only be used when an array is supplied and the type of the items requested is the component type of the array, or if varargs are used and there are 9 or more arguments.- Parameters:
varargs- a Coord varargs or Coord array; remember that varargs allocate- Returns:
- a new CoordSet that holds the given items
-
getSerializersNeeded
-