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 class
ArrayModifiableIntegerDBIDs.Itr
Iterator class.private class
ArrayModifiableIntegerDBIDs.Slice
Slice of an array.
-
Field Summary
Fields Modifier and Type Field Description static int
INITIAL_SIZE
Initial size.private int
size
Occupied size.private int[]
store
The backing array list.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ArrayModifiableIntegerDBIDs()
Constructor.protected
ArrayModifiableIntegerDBIDs(int isize)
Constructor.protected
ArrayModifiableIntegerDBIDs(DBIDs existing)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 positionindex
.int
binarySearch(DBIDRef key)
Search for the position of the given key, assuming that the data set is sorted.ArrayModifiableIntegerDBIDs
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)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.void
remove(int index)
Remove the entry at position i by shifting the remainder forward.boolean
remove(DBIDRef o)
Remove a single DBID from the collection.boolean
removeDBIDs(DBIDs ids)
Remove DBIDs from collection.void
removeSwap(int index)
Remove the entry at position i by swapping with the last (not preserving the order).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(int start, int end, java.util.Comparator<? super DBIDRef> comparator)
Sort the DBID set.void
sort(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()
-
-
-
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:DBIDs
Retrieve the collection / data size.- Specified by:
size
in interfaceArrayDBIDs
- Specified by:
size
in interfaceDBIDs
- Returns:
- collection size
-
get
public DBID get(int i)
Description copied from interface:ArrayDBIDs
Get the i'th entry (starting at 0)If possible, use an
DBIDArrayIter
viaArrayDBIDs.iter()
instead, or anDBIDVar
viaArrayDBIDs.assignVar(int, elki.database.ids.DBIDVar)
- Specified by:
get
in interfaceArrayDBIDs
- Parameters:
i
- Index- Returns:
- DBID of i'th entry.
-
assignVar
public DBIDVar assignVar(int index, DBIDVar var)
Description copied from interface:ArrayDBIDs
Assign a DBID variable the value of positionindex
.- Specified by:
assignVar
in 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:ModifiableDBIDs
Add DBIDs to collection.- Specified by:
addDBIDs
in interfaceModifiableDBIDs
- Parameters:
ids
- IDs to add.- Returns:
true
if the collection changed.
-
removeDBIDs
public boolean removeDBIDs(DBIDs ids)
Description copied from interface:ModifiableDBIDs
Remove DBIDs from collection.- Specified by:
removeDBIDs
in interfaceModifiableDBIDs
- Parameters:
ids
- IDs to remove.- Returns:
true
if the collection changed.
-
add
public boolean add(DBIDRef e)
Description copied from interface:ModifiableDBIDs
Add a single DBID to the collection.- Specified by:
add
in interfaceModifiableDBIDs
- Parameters:
e
- ID to add- Returns:
true
if the collection changed.
-
remove
public boolean remove(DBIDRef o)
Description copied from interface:ModifiableDBIDs
Remove a single DBID from the collection.- Specified by:
remove
in interfaceModifiableDBIDs
- Parameters:
o
- ID to remove- Returns:
true
if the collection changed.
-
set
public void set(int index, DBIDRef element)
Description copied from interface:ArrayModifiableDBIDs
Replace the i'th entry (starting at 0)- Specified by:
set
in interfaceArrayModifiableDBIDs
- Parameters:
index
- Indexelement
- New value
-
insert
public void insert(int i, DBIDRef newval)
Description copied from interface:ArrayModifiableDBIDs
Insert 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:
insert
in interfaceArrayModifiableDBIDs
- Parameters:
i
- Indexnewval
- New value
-
remove
public void remove(int index)
Description copied from interface:ArrayModifiableDBIDs
Remove the entry at position i by shifting the remainder forward.- Specified by:
remove
in interfaceArrayModifiableDBIDs
- Parameters:
index
- Index
-
removeSwap
public void removeSwap(int index)
Description copied from interface:ArrayModifiableDBIDs
Remove the entry at position i by swapping with the last (not preserving the order).- Specified by:
removeSwap
in interfaceArrayModifiableDBIDs
- Parameters:
index
- Entry offset to remove
-
clear
public ArrayModifiableIntegerDBIDs clear()
Description copied from interface:ModifiableDBIDs
Clear this collection.- Specified by:
clear
in interfaceArrayModifiableDBIDs
- Specified by:
clear
in interfaceModifiableDBIDs
-
binarySearch
public int binarySearch(DBIDRef key)
Description copied from interface:ArrayDBIDs
Search 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:
binarySearch
in interfaceArrayDBIDs
- Parameters:
key
- Key to search for- Returns:
- Offset of key
-
contains
public boolean contains(DBIDRef o)
Description copied from interface:DBIDs
Test whether an ID is contained.
-
sort
public void sort()
Description copied from interface:ArrayModifiableDBIDs
Sort the DBID set.- Specified by:
sort
in interfaceArrayModifiableDBIDs
-
sort
public void sort(java.util.Comparator<? super DBIDRef> comparator)
Description copied from interface:ArrayModifiableDBIDs
Sort the DBID set.- Specified by:
sort
in interfaceArrayModifiableDBIDs
- Parameters:
comparator
- Comparator to use
-
sort
public void sort(int start, int end, java.util.Comparator<? super DBIDRef> comparator)
Description copied from interface:ArrayModifiableDBIDs
Sort the DBID set.- Specified by:
sort
in 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:ArrayModifiableDBIDs
Swap DBIDs add positions a and b.- Specified by:
swap
in interfaceArrayModifiableDBIDs
- Parameters:
a
- First positionb
- Second position
-
pop
public DBIDVar pop(DBIDVar var)
Description copied from interface:ModifiableDBIDs
Pop (get and remove) one DBID from the set, into a variable.- Specified by:
pop
in interfaceModifiableDBIDs
- Parameters:
var
- Output variable- Returns:
- Always
outvar
, for inlining
-
slice
public ArrayModifiableIntegerDBIDs.Slice slice(int begin, int end)
Description copied from interface:ArrayDBIDs
Slice a subarray (as view, not copy!)- Specified by:
slice
in interfaceArrayDBIDs
- Specified by:
slice
in interfaceIntegerArrayDBIDs
- Parameters:
begin
- Begin (inclusive)end
- End (exclusive)- Returns:
- Array slice.
-
iter
public ArrayModifiableIntegerDBIDs.Itr iter()
Description copied from interface:ModifiableDBIDs
Get 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:
iter
in interfaceArrayDBIDs
- Specified by:
iter
in interfaceArrayModifiableDBIDs
- Specified by:
iter
in interfaceDBIDs
- Specified by:
iter
in interfaceIntegerArrayDBIDs
- Specified by:
iter
in interfaceIntegerDBIDs
- Specified by:
iter
in interfaceModifiableDBIDs
- Returns:
- modifiable iterator
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-