class ArrayModifiableIntegerDBIDs extends java.lang.Object implements ArrayModifiableDBIDs, IntegerArrayDBIDs
Modifier and Type | Class and Description |
---|---|
private class |
ArrayModifiableIntegerDBIDs.Itr
Iterator class.
|
private class |
ArrayModifiableIntegerDBIDs.Slice
Slice of an array.
|
Modifier and Type | Field and Description |
---|---|
static int |
INITIAL_SIZE
Initial size.
|
private int |
size
Occupied size.
|
private int[] |
store
The backing array list.
|
Modifier | Constructor and Description |
---|---|
protected |
ArrayModifiableIntegerDBIDs()
Constructor.
|
protected |
ArrayModifiableIntegerDBIDs(DBIDs existing)
Constructor.
|
protected |
ArrayModifiableIntegerDBIDs(int isize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(DBIDRef e)
Add a single DBID to the collection.
|
boolean |
addDBIDs(DBIDs ids)
Add DBIDs to collection.
|
DBIDVar |
assignVar(int index,
DBIDVar var)
Assign a DBID variable the value of position
index . |
int |
binarySearch(DBIDRef key)
Search for the position of the given key, assuming that the data set is
sorted.
|
void |
clear()
Clear this collection.
|
boolean |
contains(DBIDRef o)
Test whether an ID is contained.
|
private void |
ensureSize(int minsize)
Resize as desired.
|
DBID |
get(int i)
Get the i'th entry (starting at 0)
If possible, use an
DBIDArrayIter via ArrayDBIDs.iter() instead, or
an DBIDVar via ArrayDBIDs.assignVar(int, de.lmu.ifi.dbs.elki.database.ids.DBIDVar) |
private void |
grow()
Grow array by 50%.
|
void |
insert(int i,
DBIDRef newval)
Insert at position i (starting at 0, moving the remainder by one position).
|
ArrayModifiableIntegerDBIDs.Itr |
iter()
Get a modifiable DBID iterator (a more efficient API).
|
DBIDVar |
pop(DBIDVar var)
Pop (get and remove) one DBID from the set, into a variable.
|
boolean |
remove(DBIDRef o)
Remove a single DBID from the collection.
|
void |
remove(int index)
Remove the i'th entry (starting at 0)
|
boolean |
removeDBIDs(DBIDs ids)
Remove DBIDs from collection.
|
void |
set(int index,
DBIDRef element)
Replace the i'th entry (starting at 0)
|
int |
size()
Retrieve the collection / data size.
|
ArrayModifiableIntegerDBIDs.Slice |
slice(int begin,
int end)
Slice a subarray (as view, not copy!)
|
void |
sort()
Sort the DBID set.
|
void |
sort(java.util.Comparator<? super DBIDRef> comparator)
Sort the DBID set.
|
void |
sort(int start,
int end,
java.util.Comparator<? super DBIDRef> comparator)
Sort the DBID set.
|
void |
swap(int a,
int b)
Swap DBIDs add positions a and b.
|
java.lang.String |
toString() |
private int[] store
private int size
public static final int INITIAL_SIZE
protected ArrayModifiableIntegerDBIDs(int isize)
isize
- Initial sizeprotected ArrayModifiableIntegerDBIDs()
protected ArrayModifiableIntegerDBIDs(DBIDs existing)
existing
- Existing idspublic int size()
DBIDs
size
in interface ArrayDBIDs
size
in interface DBIDs
public DBID get(int i)
ArrayDBIDs
If possible, use an DBIDArrayIter
via ArrayDBIDs.iter()
instead, or
an DBIDVar
via ArrayDBIDs.assignVar(int, de.lmu.ifi.dbs.elki.database.ids.DBIDVar)
get
in interface ArrayDBIDs
i
- Indexpublic DBIDVar assignVar(int index, DBIDVar var)
ArrayDBIDs
index
.assignVar
in interface ArrayDBIDs
index
- Positionvar
- Variable to assign the value to.private void ensureSize(int minsize)
minsize
- Desired sizeprivate void grow()
public boolean addDBIDs(DBIDs ids)
ModifiableDBIDs
addDBIDs
in interface ModifiableDBIDs
ids
- IDs to add.true
if the collection changed.public boolean removeDBIDs(DBIDs ids)
ModifiableDBIDs
removeDBIDs
in interface ModifiableDBIDs
ids
- IDs to remove.true
if the collection changed.public boolean add(DBIDRef e)
ModifiableDBIDs
add
in interface ModifiableDBIDs
e
- ID to addtrue
if the collection changed.public boolean remove(DBIDRef o)
ModifiableDBIDs
remove
in interface ModifiableDBIDs
o
- ID to removetrue
if the collection changed.public void set(int index, DBIDRef element)
ArrayModifiableDBIDs
set
in interface ArrayModifiableDBIDs
index
- Indexelement
- New valuepublic void insert(int i, DBIDRef newval)
ArrayModifiableDBIDs
insert
in interface ArrayModifiableDBIDs
i
- Indexnewval
- New valuepublic void remove(int index)
ArrayModifiableDBIDs
remove
in interface ArrayModifiableDBIDs
index
- Indexpublic void clear()
ModifiableDBIDs
clear
in interface ModifiableDBIDs
public int binarySearch(DBIDRef key)
ArrayDBIDs
For keys not found, -(1+insertion position)
is returned, as
for Java Collections.binarySearch(java.util.List<? extends java.lang.Comparable<? super T>>, T)
binarySearch
in interface ArrayDBIDs
key
- Key to search forpublic boolean contains(DBIDRef o)
DBIDs
public void sort()
ArrayModifiableDBIDs
sort
in interface ArrayModifiableDBIDs
public void sort(java.util.Comparator<? super DBIDRef> comparator)
ArrayModifiableDBIDs
sort
in interface ArrayModifiableDBIDs
comparator
- Comparator to usepublic void sort(int start, int end, java.util.Comparator<? super DBIDRef> comparator)
ArrayModifiableDBIDs
sort
in interface ArrayModifiableDBIDs
start
- Starting index, for partial sortingend
- End index, for partial sorting (exclusive)comparator
- Comparator to usepublic void swap(int a, int b)
ArrayModifiableDBIDs
swap
in interface ArrayModifiableDBIDs
a
- First positionb
- Second positionpublic DBIDVar pop(DBIDVar var)
ModifiableDBIDs
pop
in interface ModifiableDBIDs
var
- Output variableoutvar
, for inliningpublic ArrayModifiableIntegerDBIDs.Slice slice(int begin, int end)
ArrayDBIDs
slice
in interface ArrayDBIDs
slice
in interface IntegerArrayDBIDs
begin
- Begin (inclusive)end
- End (exclusive)public ArrayModifiableIntegerDBIDs.Itr iter()
ModifiableDBIDs
for(DBIDMIter iter = ids.iter(); iter.valid(); iter.advance()) {
DBID id = iter.getDBID();
iter.remove();
}
iter
in interface ArrayDBIDs
iter
in interface ArrayModifiableDBIDs
iter
in interface DBIDs
iter
in interface IntegerArrayDBIDs
iter
in interface IntegerDBIDs
iter
in interface ModifiableDBIDs
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2019 ELKI Development Team. License information.