public class ByteArraySet extends AbstractByteSet implements java.io.Serializable, java.lang.Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
a
The backing array (valid up to
size, excluded). |
protected int |
size
The number of valid entries in
a. |
| Constructor and Description |
|---|
ByteArraySet()
Creates a new empty array set.
|
ByteArraySet(byte[] a)
Creates a new array set using the given backing array.
|
ByteArraySet(byte[] a,
int size)
Creates a new array set using the given backing array and the given number of elements of the array.
|
ByteArraySet(it.unimi.dsi.fastutil.bytes.ByteCollection c)
Creates a new array set copying the contents of a given collection.
|
ByteArraySet(ByteSet c)
Creates a new array set copying the contents of a given collection.
|
ByteArraySet(java.util.Collection<? extends java.lang.Byte> c)
Creates a new array set copying the contents of a given set.
|
ByteArraySet(int capacity)
Creates a new empty array set of given initial capacity.
|
ByteArraySet(java.util.Set<? extends java.lang.Byte> c)
Creates a new array set copying the contents of a given set.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(byte k) |
void |
clear() |
ByteArraySet |
clone()
Returns a deep copy of this set.
|
boolean |
contains(byte k) |
boolean |
isEmpty() |
it.unimi.dsi.fastutil.bytes.ByteIterator |
iterator()
Returns a type-specific iterator on the elements of this set.
|
static ByteArraySet |
of()
Creates a new empty array set.
|
static ByteArraySet |
of(byte... a)
Creates a new array set using an array of elements.
|
static ByteArraySet |
of(byte e)
Creates a new array set using the element given.
|
static ByteArraySet |
ofUnchecked()
Creates a new empty array set.
|
static ByteArraySet |
ofUnchecked(byte... a)
Creates a new array set using an array of elements.
|
boolean |
remove(byte k)
Removes an element from this set.
|
int |
size() |
it.unimi.dsi.fastutil.bytes.ByteSpliterator |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
byte[] |
toArray(byte[] a) |
byte[] |
toByteArray() |
equals, hashCode, remadd, addAll, addAll, contains, containsAll, containsAll, remove, removeAll, removeAll, retainAll, retainAll, toByteArray, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitprotected transient byte[] a
size, excluded).protected int size
a.public ByteArraySet(byte[] a)
It is the responsibility of the caller to ensure that the elements of a are distinct.
a - the backing array.public ByteArraySet()
public ByteArraySet(int capacity)
capacity - the initial capacity.public ByteArraySet(it.unimi.dsi.fastutil.bytes.ByteCollection c)
c - a collection.public ByteArraySet(java.util.Collection<? extends java.lang.Byte> c)
c - a collection.public ByteArraySet(ByteSet c)
c - a collection.public ByteArraySet(java.util.Set<? extends java.lang.Byte> c)
c - a collection.public ByteArraySet(byte[] a,
int size)
It is the responsibility of the caller to ensure that the first size elements of a are distinct.
a - the backing array.size - the number of valid elements in a.public static ByteArraySet of()
public static ByteArraySet of(byte e)
public static ByteArraySet of(byte... a)
Unlike the array accepting constructors, this method will throw if duplicate elements
are encountered. This adds a non-trivial validation burden. Use ofUnchecked() if you
know your input has no duplicates, which will skip this validation.
public static ByteArraySet ofUnchecked()
public static ByteArraySet ofUnchecked(byte... a)
It is the responsibility of the caller to ensure that the elements of a are distinct.
a - the backing array of the returned array set.a.public it.unimi.dsi.fastutil.bytes.ByteIterator iterator()
ByteSetiterator in interface it.unimi.dsi.fastutil.bytes.ByteCollectioniterator in interface it.unimi.dsi.fastutil.bytes.ByteIterableiterator in interface ByteSetiterator in interface java.lang.Iterable<java.lang.Byte>iterator in interface java.util.Collection<java.lang.Byte>iterator in interface java.util.Set<java.lang.Byte>iterator in class AbstractByteSetpublic it.unimi.dsi.fastutil.bytes.ByteSpliterator spliterator()
Set spliterators must report at least Spliterator.DISTINCT.
See Set.spliterator() for more documentation on the requirements
of the returned spliterator.
In addition to the usual trait of DISTINCT for
sets, the returned spliterator will also report
the trait ORDERED.
The returned spliterator is late-binding; it will track structural changes
after the current item, up until the first trySplit(),
at which point the maximum index will be fixed.
Structural changes before the current item or after the first
trySplit() will result in unspecified behavior.
spliterator in interface it.unimi.dsi.fastutil.bytes.ByteCollectionspliterator in interface it.unimi.dsi.fastutil.bytes.ByteIterablespliterator in interface ByteSetspliterator in interface java.lang.Iterable<java.lang.Byte>spliterator in interface java.util.Collection<java.lang.Byte>spliterator in interface java.util.Set<java.lang.Byte>public boolean contains(byte k)
contains in interface it.unimi.dsi.fastutil.bytes.ByteCollectioncontains in class it.unimi.dsi.fastutil.bytes.AbstractByteCollectionpublic int size()
size in interface java.util.Collection<java.lang.Byte>size in interface java.util.Set<java.lang.Byte>size in class java.util.AbstractCollection<java.lang.Byte>public boolean remove(byte k)
AbstractByteSetrem() method
implemented by type-specific abstract Collection superclass.remove in interface ByteSetremove in class AbstractByteSetCollection.remove(Object)public boolean add(byte k)
add in interface it.unimi.dsi.fastutil.bytes.ByteCollectionadd in class it.unimi.dsi.fastutil.bytes.AbstractByteCollectionpublic void clear()
clear in interface java.util.Collection<java.lang.Byte>clear in interface java.util.Set<java.lang.Byte>clear in class java.util.AbstractCollection<java.lang.Byte>public boolean isEmpty()
isEmpty in interface java.util.Collection<java.lang.Byte>isEmpty in interface java.util.Set<java.lang.Byte>isEmpty in class java.util.AbstractCollection<java.lang.Byte>public byte[] toByteArray()
toByteArray in interface it.unimi.dsi.fastutil.bytes.ByteCollectiontoByteArray in class it.unimi.dsi.fastutil.bytes.AbstractByteCollectionpublic byte[] toArray(byte[] a)
toArray in interface it.unimi.dsi.fastutil.bytes.ByteCollectiontoArray in class it.unimi.dsi.fastutil.bytes.AbstractByteCollectionpublic ByteArraySet clone()
This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
clone in class java.lang.Object