Package elki.database.ids.integer
Class ArrayModifiableIntegerDBIDs
- java.lang.Object
-
- elki.database.ids.integer.ArrayModifiableIntegerDBIDs
-
- All Implemented Interfaces:
ArrayDBIDs,ArrayModifiableDBIDs,DBIDs,IntegerArrayDBIDs,IntegerDBIDs,ModifiableDBIDs
class ArrayModifiableIntegerDBIDs extends java.lang.Object implements ArrayModifiableDBIDs, IntegerArrayDBIDs
Class using a primitive int[] array as storage.- Since:
- 0.6.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classArrayModifiableIntegerDBIDs.ItrIterator class.private classArrayModifiableIntegerDBIDs.SliceSlice of an array.
-
Field Summary
Fields Modifier and Type Field Description static intINITIAL_SIZEInitial size.private intsizeOccupied size.private int[]storeThe backing array list.
-
Constructor Summary
Constructors Modifier Constructor Description protectedArrayModifiableIntegerDBIDs()Constructor.protectedArrayModifiableIntegerDBIDs(int isize)Constructor.protectedArrayModifiableIntegerDBIDs(DBIDs existing)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(DBIDRef e)Add a single DBID to the collection.booleanaddDBIDs(DBIDs ids)Add DBIDs to collection.DBIDVarassignVar(int index, DBIDVar var)Assign a DBID variable the value of positionindex.intbinarySearch(DBIDRef key)Search for the position of the given key, assuming that the data set is sorted.ArrayModifiableIntegerDBIDsclear()Clear this collection.booleancontains(DBIDRef o)Test whether an ID is contained.private voidensureSize(int minsize)Resize as desired.DBIDget(int i)Get the i'th entry (starting at 0)private voidgrow()Grow array by 50%.voidinsert(int i, DBIDRef newval)Insert at position i (starting at 0, moving the remainder by one position).ArrayModifiableIntegerDBIDs.Itriter()Get a modifiable DBID iterator (a more efficient API).DBIDVarpop(DBIDVar var)Pop (get and remove) one DBID from the set, into a variable.voidremove(int index)Remove the entry at position i by shifting the remainder forward.booleanremove(DBIDRef o)Remove a single DBID from the collection.booleanremoveDBIDs(DBIDs ids)Remove DBIDs from collection.voidremoveSwap(int index)Remove the entry at position i by swapping with the last (not preserving the order).voidset(int index, DBIDRef element)Replace the i'th entry (starting at 0)intsize()Retrieve the collection / data size.ArrayModifiableIntegerDBIDs.Sliceslice(int begin, int end)Slice a subarray (as view, not copy!)voidsort()Sort the DBID set.voidsort(int start, int end, java.util.Comparator<? super DBIDRef> comparator)Sort the DBID set.voidsort(java.util.Comparator<? super DBIDRef> comparator)Sort the DBID set.voidswap(int a, int b)Swap DBIDs add positions a and b.java.lang.StringtoString()
-
-
-
Field Detail
-
store
private int[] store
The backing array list.
-
size
private int size
Occupied size.
-
INITIAL_SIZE
public static final int INITIAL_SIZE
Initial size.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ArrayModifiableIntegerDBIDs
protected ArrayModifiableIntegerDBIDs(int isize)
Constructor.- Parameters:
isize- Initial size
-
ArrayModifiableIntegerDBIDs
protected ArrayModifiableIntegerDBIDs()
Constructor.
-
ArrayModifiableIntegerDBIDs
protected ArrayModifiableIntegerDBIDs(DBIDs existing)
Constructor.- Parameters:
existing- Existing ids
-
-
Method Detail
-
size
public int size()
Description copied from interface:DBIDsRetrieve the collection / data size.- Specified by:
sizein interfaceArrayDBIDs- Specified by:
sizein interfaceDBIDs- Returns:
- collection size
-
get
public DBID get(int i)
Description copied from interface:ArrayDBIDsGet the i'th entry (starting at 0)If possible, use an
DBIDArrayIterviaArrayDBIDs.iter()instead, or anDBIDVarviaArrayDBIDs.assignVar(int, elki.database.ids.DBIDVar)- Specified by:
getin interfaceArrayDBIDs- Parameters:
i- Index- Returns:
- DBID of i'th entry.
-
assignVar
public DBIDVar assignVar(int index, DBIDVar var)
Description copied from interface:ArrayDBIDsAssign a DBID variable the value of positionindex.- Specified by:
assignVarin interfaceArrayDBIDs- Parameters:
index- Positionvar- Variable to assign the value to.
-
ensureSize
private void ensureSize(int minsize)
Resize as desired.- Parameters:
minsize- Desired size
-
grow
private void grow()
Grow array by 50%.
-
addDBIDs
public boolean addDBIDs(DBIDs ids)
Description copied from interface:ModifiableDBIDsAdd DBIDs to collection.- Specified by:
addDBIDsin interfaceModifiableDBIDs- Parameters:
ids- IDs to add.- Returns:
trueif the collection changed.
-
removeDBIDs
public boolean removeDBIDs(DBIDs ids)
Description copied from interface:ModifiableDBIDsRemove DBIDs from collection.- Specified by:
removeDBIDsin interfaceModifiableDBIDs- Parameters:
ids- IDs to remove.- Returns:
trueif the collection changed.
-
add
public boolean add(DBIDRef e)
Description copied from interface:ModifiableDBIDsAdd a single DBID to the collection.- Specified by:
addin interfaceModifiableDBIDs- Parameters:
e- ID to add- Returns:
trueif the collection changed.
-
remove
public boolean remove(DBIDRef o)
Description copied from interface:ModifiableDBIDsRemove a single DBID from the collection.- Specified by:
removein interfaceModifiableDBIDs- Parameters:
o- ID to remove- Returns:
trueif the collection changed.
-
set
public void set(int index, DBIDRef element)Description copied from interface:ArrayModifiableDBIDsReplace the i'th entry (starting at 0)- Specified by:
setin interfaceArrayModifiableDBIDs- Parameters:
index- Indexelement- New value
-
insert
public void insert(int i, DBIDRef newval)Description copied from interface:ArrayModifiableDBIDsInsert at position i (starting at 0, moving the remainder by one position).Note: this operation has linear time complexity on average: O(n/2)
- Specified by:
insertin interfaceArrayModifiableDBIDs- Parameters:
i- Indexnewval- New value
-
remove
public void remove(int index)
Description copied from interface:ArrayModifiableDBIDsRemove the entry at position i by shifting the remainder forward.- Specified by:
removein interfaceArrayModifiableDBIDs- Parameters:
index- Index
-
removeSwap
public void removeSwap(int index)
Description copied from interface:ArrayModifiableDBIDsRemove the entry at position i by swapping with the last (not preserving the order).- Specified by:
removeSwapin interfaceArrayModifiableDBIDs- Parameters:
index- Entry offset to remove
-
clear
public ArrayModifiableIntegerDBIDs clear()
Description copied from interface:ModifiableDBIDsClear this collection.- Specified by:
clearin interfaceArrayModifiableDBIDs- Specified by:
clearin interfaceModifiableDBIDs
-
binarySearch
public int binarySearch(DBIDRef key)
Description copied from interface:ArrayDBIDsSearch for the position of the given key, assuming that the data set is sorted. For unsorted arrays, the result is undefined.For keys not found,
-(1+insertion position)is returned, as for JavaCollections.binarySearch(java.util.List<? extends java.lang.Comparable<? super T>>, T)- Specified by:
binarySearchin interfaceArrayDBIDs- Parameters:
key- Key to search for- Returns:
- Offset of key
-
contains
public boolean contains(DBIDRef o)
Description copied from interface:DBIDsTest whether an ID is contained.
-
sort
public void sort()
Description copied from interface:ArrayModifiableDBIDsSort the DBID set.- Specified by:
sortin interfaceArrayModifiableDBIDs
-
sort
public void sort(java.util.Comparator<? super DBIDRef> comparator)
Description copied from interface:ArrayModifiableDBIDsSort the DBID set.- Specified by:
sortin interfaceArrayModifiableDBIDs- Parameters:
comparator- Comparator to use
-
sort
public void sort(int start, int end, java.util.Comparator<? super DBIDRef> comparator)Description copied from interface:ArrayModifiableDBIDsSort the DBID set.- Specified by:
sortin interfaceArrayModifiableDBIDs- Parameters:
start- Starting index, for partial sortingend- End index, for partial sorting (exclusive)comparator- Comparator to use
-
swap
public void swap(int a, int b)Description copied from interface:ArrayModifiableDBIDsSwap DBIDs add positions a and b.- Specified by:
swapin interfaceArrayModifiableDBIDs- Parameters:
a- First positionb- Second position
-
pop
public DBIDVar pop(DBIDVar var)
Description copied from interface:ModifiableDBIDsPop (get and remove) one DBID from the set, into a variable.- Specified by:
popin interfaceModifiableDBIDs- Parameters:
var- Output variable- Returns:
- Always
outvar, for inlining
-
slice
public ArrayModifiableIntegerDBIDs.Slice slice(int begin, int end)
Description copied from interface:ArrayDBIDsSlice a subarray (as view, not copy!)- Specified by:
slicein interfaceArrayDBIDs- Specified by:
slicein interfaceIntegerArrayDBIDs- Parameters:
begin- Begin (inclusive)end- End (exclusive)- Returns:
- Array slice.
-
iter
public ArrayModifiableIntegerDBIDs.Itr iter()
Description copied from interface:ModifiableDBIDsGet a modifiable DBID iterator (a more efficient API).usage example:
for(DBIDMIter iter = ids.iter(); iter.valid(); iter.advance()) { DBID id = iter.getDBID(); iter.remove(); }- Specified by:
iterin interfaceArrayDBIDs- Specified by:
iterin interfaceArrayModifiableDBIDs- Specified by:
iterin interfaceDBIDs- Specified by:
iterin interfaceIntegerArrayDBIDs- Specified by:
iterin interfaceIntegerDBIDs- Specified by:
iterin interfaceModifiableDBIDs- Returns:
- modifiable iterator
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-