public final class DBIDUtil extends Object
Modifier and Type | Field and Description |
---|---|
static EmptyDBIDs |
EMPTYDBIDS
Final, global copy of empty DBIDs.
|
Modifier | Constructor and Description |
---|---|
private |
DBIDUtil()
Static - no public constructor.
|
Modifier and Type | Method and Description |
---|---|
static int |
asInteger(DBIDRef id)
Export a DBID as int.
|
static int |
compare(DBIDRef id1,
DBIDRef id2)
Compare two DBIDs.
|
static void |
deallocateDBIDRange(DBIDRange range)
Deallocate a static DBID range.
|
static void |
deallocateSingleDBID(DBID id)
Return a single DBID for reuse.
|
static DBID |
deref(DBIDRef ref)
Dereference a DBID reference.
|
static ModifiableDBIDs |
difference(DBIDs ids1,
DBIDs ids2)
Returns the difference of the two specified collection of IDs.
|
static ArrayDBIDs |
ensureArray(DBIDs ids)
Ensure that the given DBIDs are array-indexable.
|
static ModifiableDBIDs |
ensureModifiable(DBIDs ids)
Ensure modifiable.
|
static SetDBIDs |
ensureSet(DBIDs ids)
Ensure that the given DBIDs support fast "contains" operations.
|
static boolean |
equal(DBIDRef id1,
DBIDRef id2)
Test two DBIDs for equality.
|
static DBID |
generateSingleDBID()
Generate a single DBID.
|
static DBIDRange |
generateStaticDBIDRange(int size)
Generate a static DBID range.
|
static ByteBufferSerializer<DBID> |
getDBIDSerializer()
Get a serializer for DBIDs.
|
static ByteBufferSerializer<DBID> |
getDBIDSerializerStatic()
Get a serializer for DBIDs with static size.
|
static DBID |
importInteger(int id)
Import and integer as DBID.
|
private static int |
internalIntersectionSize(DBIDs first,
DBIDs second)
Compute the set intersection size of two sets.
|
static ModifiableDBIDs |
intersection(DBIDs first,
DBIDs second)
Compute the set intersection of two sets.
|
static int |
intersectionSize(DBIDs first,
DBIDs second)
Compute the set intersection size of two sets.
|
static DBIDRef |
invalid()
Get the invalid special ID.
|
static StaticDBIDs |
makeUnmodifiable(DBIDs existing)
Wrap an existing DBIDs collection to be unmodifiable.
|
static ArrayModifiableDBIDs |
newArray()
Make a new (modifiable) array of DBIDs.
|
static ArrayModifiableDBIDs |
newArray(DBIDs existing)
Make a new (modifiable) array of DBIDs.
|
static ArrayModifiableDBIDs |
newArray(int size)
Make a new (modifiable) array of DBIDs.
|
static <D extends Distance<D>> |
newDistancePair(D dist,
DBIDRef id)
Make a DistanceDBIDPair.
|
static DoubleDistanceDBIDPair |
newDistancePair(double dist,
DBIDRef id)
Make a DoubleDistanceDBIDPair.
|
static DoubleDistanceKNNHeap |
newDoubleDistanceHeap(int k)
Create an appropriate heap for double distances.
|
static HashSetModifiableDBIDs |
newHashSet()
Make a new (modifiable) hash set of DBIDs.
|
static HashSetModifiableDBIDs |
newHashSet(DBIDs existing)
Make a new (modifiable) hash set of DBIDs.
|
static HashSetModifiableDBIDs |
newHashSet(int size)
Make a new (modifiable) hash set of DBIDs.
|
static <D extends Distance<D>> |
newHeap(D distancetype,
int k)
Create an appropriate heap for the distance type.
|
static <D extends Distance<D>> |
newHeap(KNNList<D> exist)
Build a new heap from a given list.
|
static DBIDPair |
newPair(DBIDRef id1,
DBIDRef id2)
Make a DBID pair.
|
static DoubleDBIDPair |
newPair(double val,
DBIDRef id)
Make a DoubleDBIDPair.
|
static DBIDVar |
newVar()
Make a new DBID variable.
|
static DBIDVar |
newVar(DBIDRef val)
Make a new DBID variable.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
int seed)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
Long seed)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
Random random)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
RandomFactory rnd)
Produce a random sample of the given DBIDs.
|
static void |
randomShuffle(ArrayModifiableDBIDs ids,
Random random)
Produce a random shuffling of the given DBID array.
|
static void |
randomShuffle(ArrayModifiableDBIDs ids,
RandomFactory rnd)
Produce a random shuffling of the given DBID array.
|
static void |
randomShuffle(ArrayModifiableDBIDs ids,
Random random,
int limit)
Produce a random shuffling of the given DBID array.
|
static ArrayDBIDs[] |
randomSplit(DBIDs oids,
int p,
Random random)
Randomly split IDs into
p partitions of almost-equal size. |
static ArrayDBIDs[] |
randomSplit(DBIDs ids,
int p,
RandomFactory rnd)
Randomly split IDs into
p partitions of almost-equal size. |
static <D extends Distance<D>> |
subList(KNNList<D> list,
int k)
Get a subset of the KNN result.
|
static void |
symmetricIntersection(DBIDs first,
DBIDs second,
HashSetModifiableDBIDs firstonly,
HashSetModifiableDBIDs intersection,
HashSetModifiableDBIDs secondonly)
Compute the set symmetric intersection of two sets.
|
static String |
toString(DBIDRef id)
Format a DBID as string.
|
static String |
toString(DBIDs ids)
Format a DBID as string.
|
static ModifiableDBIDs |
union(DBIDs ids1,
DBIDs ids2)
Returns the union of the two specified collection of IDs.
|
public static final EmptyDBIDs EMPTYDBIDS
public static DBIDRef invalid()
public static DBID importInteger(int id)
id
- Integer ID to importpublic static int asInteger(DBIDRef id)
id
- DBID to exportpublic static int compare(DBIDRef id1, DBIDRef id2)
id1
- First IDid2
- Second IDpublic static boolean equal(DBIDRef id1, DBIDRef id2)
id1
- First IDid2
- Second IDpublic static DBID deref(DBIDRef ref)
ref
- DBID referencepublic static String toString(DBIDRef id)
id
- DBIDpublic static String toString(DBIDs ids)
ids
- DBIDspublic static ByteBufferSerializer<DBID> getDBIDSerializer()
public static ByteBufferSerializer<DBID> getDBIDSerializerStatic()
public static DBID generateSingleDBID()
public static void deallocateSingleDBID(DBID id)
id
- DBID to deallocatepublic static DBIDRange generateStaticDBIDRange(int size)
size
- Requested sizepublic static void deallocateDBIDRange(DBIDRange range)
range
- Range to deallocatepublic static DBIDVar newVar(DBIDRef val)
val
- Initial value.public static DBIDVar newVar()
public static ArrayModifiableDBIDs newArray()
public static HashSetModifiableDBIDs newHashSet()
public static ArrayModifiableDBIDs newArray(int size)
size
- Size hintpublic static HashSetModifiableDBIDs newHashSet(int size)
size
- Size hintpublic static ArrayModifiableDBIDs newArray(DBIDs existing)
existing
- Existing DBIDspublic static HashSetModifiableDBIDs newHashSet(DBIDs existing)
existing
- Existing DBIDspublic static ModifiableDBIDs intersection(DBIDs first, DBIDs second)
first
- First setsecond
- Second setpublic static int intersectionSize(DBIDs first, DBIDs second)
first
- First setsecond
- Second setprivate static int internalIntersectionSize(DBIDs first, DBIDs second)
first
- First setsecond
- Second setpublic static void symmetricIntersection(DBIDs first, DBIDs second, HashSetModifiableDBIDs firstonly, HashSetModifiableDBIDs intersection, HashSetModifiableDBIDs secondonly)
first
- First setsecond
- Second setfirstonly
- OUTPUT: elements only in first. MUST BE EMPTYintersection
- OUTPUT: elements in intersection. MUST BE EMPTYsecondonly
- OUTPUT: elements only in second. MUST BE EMPTYpublic static ModifiableDBIDs union(DBIDs ids1, DBIDs ids2)
ids1
- the first collectionids2
- the second collectionpublic static ModifiableDBIDs difference(DBIDs ids1, DBIDs ids2)
ids1
- the first collectionids2
- the second collectionpublic static StaticDBIDs makeUnmodifiable(DBIDs existing)
existing
- Existing collectionpublic static ArrayDBIDs ensureArray(DBIDs ids)
ids
- IDspublic static SetDBIDs ensureSet(DBIDs ids)
ids
- IDspublic static ModifiableDBIDs ensureModifiable(DBIDs ids)
ids
- IDspublic static DBIDPair newPair(DBIDRef id1, DBIDRef id2)
id1
- first IDid2
- second IDpublic static DoubleDBIDPair newPair(double val, DBIDRef id)
val
- double valueid
- IDpublic static <D extends Distance<D>> DistanceDBIDPair<D> newDistancePair(D dist, DBIDRef id)
dist
- Distance valueid
- IDpublic static DoubleDistanceDBIDPair newDistancePair(double dist, DBIDRef id)
dist
- Distance valueid
- IDpublic static <D extends Distance<D>> KNNHeap<D> newHeap(D distancetype, int k)
D
- distance typedistancetype
- distance prototypek
- K valuepublic static DoubleDistanceKNNHeap newDoubleDistanceHeap(int k)
k
- K valuepublic static <D extends Distance<D>> KNNHeap<D> newHeap(KNNList<D> exist)
D
- Distance typeexist
- Existing resultpublic static void randomShuffle(ArrayModifiableDBIDs ids, RandomFactory rnd)
ids
- Original DBIDsrnd
- Random generatorpublic static void randomShuffle(ArrayModifiableDBIDs ids, Random random)
ids
- Original DBIDsrandom
- Random generatorpublic static void randomShuffle(ArrayModifiableDBIDs ids, Random random, int limit)
limit
elements will be randomized.ids
- Original DBIDsrandom
- Random generatorlimit
- Shuffling limit.public static ModifiableDBIDs randomSample(DBIDs source, int k, int seed)
source
- Original DBIDsk
- k Parameterseed
- Random generator seedpublic static ModifiableDBIDs randomSample(DBIDs source, int k, Long seed)
source
- Original DBIDsk
- k Parameterseed
- Random generator seedpublic static ModifiableDBIDs randomSample(DBIDs source, int k, RandomFactory rnd)
source
- Original DBIDsk
- k Parameterrnd
- Random generatorpublic static ModifiableDBIDs randomSample(DBIDs source, int k, Random random)
source
- Original DBIDsk
- k Parameterrandom
- Random generatorpublic static ArrayDBIDs[] randomSplit(DBIDs ids, int p, RandomFactory rnd)
p
partitions of almost-equal size.ids
- Original DBIDsp
- Desired number of partitions.rnd
- Random generatorpublic static ArrayDBIDs[] randomSplit(DBIDs oids, int p, Random random)
p
partitions of almost-equal size.oids
- Original DBIDsp
- Desired number of partitions.random
- Random generator