本文整理匯總了Java中com.thinkaurelius.titan.util.datastructures.IntSet類的典型用法代碼示例。如果您正苦於以下問題:Java IntSet類的具體用法?Java IntSet怎麽用?Java IntSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IntSet類屬於com.thinkaurelius.titan.util.datastructures包,在下文中一共展示了IntSet類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testIDPoolWith
import com.thinkaurelius.titan.util.datastructures.IntSet; //導入依賴的package包/類
private void testIDPoolWith(IDPoolFactory poolFactory, final int numPartitions,
final int numThreads, final int attemptsPerThread) throws InterruptedException {
final Random random = new Random();
final IntSet[] ids = new IntSet[numPartitions];
final StandardIDPool[] idPools = new StandardIDPool[numPartitions];
for (int i = 0; i < numPartitions; i++) {
ids[i] = new IntHashSet(attemptsPerThread * numThreads / numPartitions);
int partition = i*100;
idPools[i] = poolFactory.get(partition);
}
Thread[] threads = new Thread[numThreads];
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
for (int attempt = 0; attempt < attemptsPerThread; attempt++) {
int offset = random.nextInt(numPartitions);
long id = idPools[offset].nextID();
assertTrue(id < Integer.MAX_VALUE);
IntSet idset = ids[offset];
synchronized (idset) {
assertFalse(idset.contains((int) id));
idset.add((int) id);
}
}
}
});
threads[i].start();
}
for (int i = 0; i < numThreads; i++) threads[i].join();
for (int i = 0; i < idPools.length; i++) idPools[i].close();
//Verify consecutive id assignment
for (int i = 0; i < ids.length; i++) {
IntSet set = ids[i];
int max = 0;
int[] all = set.getAll();
for (int j=0;j<all.length;j++) if (all[j]>max) max=all[j];
for (int j=1;j<=max;j++) assertTrue(i+ " contains: " + j,set.contains(j));
}
}