Package elki.database.ids.integer
Class IntegerDBID
- java.lang.Object
-
- elki.database.ids.integer.IntegerDBID
-
- All Implemented Interfaces:
ArrayDBIDs
,DBID
,DBIDRef
,DBIDs
,IntegerDBIDRef
,SetDBIDs
,java.lang.Comparable<DBIDRef>
final class IntegerDBID extends java.lang.Object implements DBID, IntegerDBIDRef
Database ID object. While this currently is just an Integer, it should be avoided to store the object IDs in regular integers to reduce problems if this API ever changes (for example if someone needs to supportlong
, it should not require changes in too many places!) In particular, a developer should not make any assumption of these IDs being consistent across multiple results/databases.- Since:
- 0.4.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IntegerDBID.DynamicSerializer
Dynamic sized serializer, using varint.protected class
IntegerDBID.Itr
Pseudo iterator for DBIDs interface.static class
IntegerDBID.StaticSerializer
Static sized serializer, using regular integers.
-
Field Summary
Fields Modifier and Type Field Description static ByteBufferSerializer<DBID>
DYNAMIC_SERIALIZER
The public instance to use for dynamic serialization.protected int
id
The actual object ID.static FixedSizeByteBufferSerializer<DBID>
STATIC_SERIALIZER
The public instance to use for static serialization.
-
Constructor Summary
Constructors Modifier Constructor Description protected
IntegerDBID(int id)
Constructor from integer id.protected
IntegerDBID(java.lang.Integer id)
Constructor from integer id.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.int
compareTo(DBIDRef o)
Compare two DBIDs for ordering.boolean
contains(DBIDRef o)
Test whether an ID is contained.boolean
equals(java.lang.Object obj)
Deprecated.DBID
get(int i)
Get the i'th entry (starting at 0)int
hashCode()
In contrast toDBIDRef
, the DBID interface is supposed to have a stable hash code.int
internalGetIndex()
Return the integer value of the object ID.boolean
isEmpty()
Test for an empty DBID collection.IntegerDBID.Itr
iter()
Iterableint
size()
Size of the DBID "collection".ArrayDBIDs
slice(int begin, int end)
Slice a subarray (as view, not copy!)java.lang.String
toString()
-
-
-
Field Detail
-
id
protected final int id
The actual object ID.
-
DYNAMIC_SERIALIZER
public static final ByteBufferSerializer<DBID> DYNAMIC_SERIALIZER
The public instance to use for dynamic serialization.
-
STATIC_SERIALIZER
public static final FixedSizeByteBufferSerializer<DBID> STATIC_SERIALIZER
The public instance to use for static serialization.
-
-
Method Detail
-
internalGetIndex
public int internalGetIndex()
Return the integer value of the object ID.- Specified by:
internalGetIndex
in interfaceDBIDRef
- Specified by:
internalGetIndex
in interfaceIntegerDBIDRef
- Returns:
- integer id
-
size
public int size()
Description copied from interface:ArrayDBIDs
Size of the DBID "collection".- Specified by:
size
in interfaceArrayDBIDs
- Specified by:
size
in interfaceDBIDs
- Returns:
- size
-
isEmpty
public boolean isEmpty()
Description copied from interface:DBIDs
Test for an empty DBID collection.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
Description copied from interface:DBID
In contrast toDBIDRef
, the DBID interface is supposed to have a stable hash code. However, it is generally preferred to use optimized storage classes instead of Java collections!
-
equals
@Deprecated public boolean equals(java.lang.Object obj)
Deprecated.Description copied from interface:DBID
In contrast toDBIDRef
, the DBID interface is supposed to have a stable equals for other DBIDs.Yet,
DBIDUtil.equal(elki.database.ids.DBIDRef, elki.database.ids.DBIDRef)
is more type safe and explicit.
-
compareTo
public int compareTo(DBIDRef o)
Description copied from interface:DBID
Compare two DBIDs for ordering.Consider using
DBIDUtil.compare(elki.database.ids.DBIDRef, elki.database.ids.DBIDRef)
, which is more explicit.
-
iter
public IntegerDBID.Itr iter()
Description copied from interface:ArrayDBIDs
Iterable- Specified by:
iter
in interfaceArrayDBIDs
- Specified by:
iter
in interfaceDBIDs
- Returns:
- Iterator
-
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.
-
contains
public boolean contains(DBIDRef o)
Description copied from interface:DBIDs
Test whether an ID is contained.
-
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
-
slice
public ArrayDBIDs slice(int begin, int end)
Description copied from interface:ArrayDBIDs
Slice a subarray (as view, not copy!)- Specified by:
slice
in interfaceArrayDBIDs
- Parameters:
begin
- Begin (inclusive)end
- End (exclusive)- Returns:
- Array slice.
-
-