public final class DBIDUtil
extends java.lang.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 DBIDRange |
assertRange(DBIDs ids)
Assert that the presented ids constitute a continuous
DBIDRange . |
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 ModifiableDBIDs |
internalIntersection(DBIDs first,
DBIDs second)
Compute the set intersection of two sets.
|
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 ModifiableDoubleDBIDList |
newDistanceDBIDList()
Create a modifiable list to store distance-DBID pairs.
|
static ModifiableDoubleDBIDList |
newDistanceDBIDList(int size)
Create a modifiable list to store distance-DBID pairs.
|
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 KNNHeap |
newHeap(int k)
Create an appropriate heap for the distance type.
|
static KNNHeap |
newHeap(KNNList 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 DBIDs |
randomSample(DBIDs ids,
double rate,
java.util.Random random)
Produce a random sample of the given DBIDs.
|
static DBIDs |
randomSample(DBIDs ids,
double rate,
RandomFactory random)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
int seed)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
java.lang.Long seed)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSample(DBIDs source,
int k,
java.util.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 DBIDVar |
randomSample(DBIDs ids,
java.util.Random random)
Draw a single random sample.
|
static DBIDVar |
randomSample(DBIDs ids,
RandomFactory random)
Draw a single random sample.
|
static ModifiableDBIDs |
randomSampleExcept(DBIDs source,
DBIDRef except,
int k,
java.util.Random random)
Produce a random sample of the given DBIDs.
|
static ModifiableDBIDs |
randomSampleExcept(DBIDs source,
DBIDRef except,
int k,
RandomFactory rnd)
Produce a random sample of the given DBIDs.
|
static void |
randomShuffle(ArrayModifiableDBIDs ids,
java.util.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,
java.util.Random random,
int limit)
Produce a random shuffling of the given DBID array.
|
static ArrayDBIDs[] |
randomSplit(DBIDs oids,
int p,
java.util.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 void |
symmetricIntersection(DBIDs first,
DBIDs second,
HashSetModifiableDBIDs firstonly,
HashSetModifiableDBIDs intersection,
HashSetModifiableDBIDs secondonly)
Compute the set symmetric intersection of two sets.
|
static java.lang.String |
toString(DBIDRef id)
Format a DBID as string.
|
static java.lang.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)
Note: this may not be possible for some factories!
id
- Integer ID to importpublic static int asInteger(DBIDRef id)
Note: this may not be possible for some factories!
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 java.lang.String toString(DBIDRef id)
id
- DBIDpublic static java.lang.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 setprivate static ModifiableDBIDs internalIntersection(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 KNNHeap newHeap(int k)
k
- K valuepublic static KNNHeap newHeap(KNNList exist)
exist
- Existing resultpublic static void randomShuffle(ArrayModifiableDBIDs ids, RandomFactory rnd)
ids
- Original DBIDs, no duplicates allowedrnd
- Random generatorpublic static void randomShuffle(ArrayModifiableDBIDs ids, java.util.Random random)
ids
- Original DBIDs, no duplicates allowedrandom
- Random generatorpublic static void randomShuffle(ArrayModifiableDBIDs ids, java.util.Random random, int limit)
limit
elements will be fully randomized, but the
remaining objects will also be changed.ids
- Original DBIDs, no duplicates allowedrandom
- Random generatorlimit
- Shuffling limit.public static ModifiableDBIDs randomSample(DBIDs source, int k, int seed)
source
- Original DBIDs, no duplicates allowedk
- k Parameterseed
- Random generator seedpublic static ModifiableDBIDs randomSample(DBIDs source, int k, java.lang.Long seed)
source
- Original DBIDs, no duplicates allowedk
- k Parameterseed
- Random generator seedpublic static ModifiableDBIDs randomSample(DBIDs source, int k, RandomFactory rnd)
source
- Original DBIDs, no duplicates allowedk
- k Parameterrnd
- Random generatorpublic static ModifiableDBIDs randomSampleExcept(DBIDs source, DBIDRef except, int k, RandomFactory rnd)
source
- Original DBIDs, no duplicates allowedexcept
- Excluded objectk
- k Parameterrnd
- Random generatorpublic static ModifiableDBIDs randomSample(DBIDs source, int k, java.util.Random random)
source
- Original DBIDs, no duplicates allowedk
- k Parameterrandom
- Random generatorpublic static ModifiableDBIDs randomSampleExcept(DBIDs source, DBIDRef except, int k, java.util.Random random)
source
- Original DBIDs, no duplicates allowedexcept
- Excluded objectk
- k Parameterrandom
- Random generatorpublic static DBIDs randomSample(DBIDs ids, double rate, RandomFactory random)
ids
- Original ids, no duplicates allowedrate
- Sampling raterandom
- Random generatorpublic static DBIDs randomSample(DBIDs ids, double rate, java.util.Random random)
ids
- Original ids, no duplicates allowedrate
- Sampling raterandom
- Random generatorpublic static DBIDVar randomSample(DBIDs ids, java.util.Random random)
ids
- IDs to draw fromrandom
- Random valuepublic static DBIDVar randomSample(DBIDs ids, RandomFactory random)
ids
- IDs to draw fromrandom
- Random valuepublic 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, java.util.Random random)
p
partitions of almost-equal size.oids
- Original DBIDsp
- Desired number of partitions.random
- Random generatorpublic static ModifiableDoubleDBIDList newDistanceDBIDList(int size)
size
- Estimated upper list sizepublic static ModifiableDoubleDBIDList newDistanceDBIDList()
public static DBIDRange assertRange(DBIDs ids)
DBIDRange
.ids
- ID range.AbortException
Copyright © 2019 ELKI Development Team. License information.