本文整理汇总了Java中it.unimi.dsi.fastutil.longs.LongArrayList.add方法的典型用法代码示例。如果您正苦于以下问题:Java LongArrayList.add方法的具体用法?Java LongArrayList.add怎么用?Java LongArrayList.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.longs.LongArrayList
的用法示例。
在下文中一共展示了LongArrayList.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
/**
* Runs PageRank, either until the max number of iterations has been reached or the L1 norm of
* the difference between PageRank vectors drops below the tolerance.
*
* @return number of iterations that was actually run
*/
public int run() {
LongArrayList noOuts = new LongArrayList();
LongIterator iter = nodes.iterator();
while (iter.hasNext()) {
long v = iter.nextLong();
if (graph.getOutDegree(v) == 0) {
noOuts.add(v);
}
}
double dampingAmount = (1.0 - dampingFactor) / nodeCount;
prVector = new double[(int) (maxNodeId + 1)];
nodes.forEach(v -> prVector[(int) (long) v] = 1.0 / nodeCount);
int i = 0;
while (i < this.maxIterations && normL1 > tolerance) {
iterate(dampingAmount, noOuts);
i++;
}
return i;
}
示例2: ListIterator
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
private ListIterator(
final int listIndex,
final int valueBitSize,
final int minIntervalSize,
final InputBitStream inputBitStream,
final PebbleBytesStore bytesStore
) throws IOException {
super(listIndex, valueBitSize, minIntervalSize, inputBitStream, bytesStore);
final long offset = inputBitStream.position();
valuesMap = new LongArrayList();
long value;
while ((value = super.nextLong()) != -1) {
valuesMap.add(value);
}
inputBitStream.position(offset);
remainingElements = inputBitStream.readDelta() + valuesMap.size();
lastIndex = 0;
}
示例3: getLongSet
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
protected LongArrayList getLongSet(long... longs) {
LongArrayList longSet = new LongArrayList();
for (long longNumber : longs) {
longSet.add(longNumber);
}
return longSet;
}
示例4: calculateConditions
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
public List<LongArrayList> calculateConditions(PositionListIndex partialUnique,
PositionListIndex PLICondition,
int frequency,
List<LongArrayList> unsatisfiedClusters) {
List<LongArrayList> result = new LinkedList<>();
Long2LongOpenHashMap uniqueHashMap = partialUnique.asHashMap();
LongArrayList touchedClusters = new LongArrayList();
nextCluster:
for (LongArrayList cluster : PLICondition.getClusters()) {
int unsatisfactionCount = 0;
touchedClusters.clear();
for (long rowNumber : cluster) {
if (uniqueHashMap.containsKey(rowNumber)) {
if (touchedClusters.contains(uniqueHashMap.get(rowNumber))) {
unsatisfactionCount++;
} else {
touchedClusters.add(uniqueHashMap.get(rowNumber));
}
}
}
if (unsatisfactionCount == 0) {
result.add(cluster);
} else {
//if ((cluster.size() - unsatisfactionCount) >= frequency) {
unsatisfiedClusters.add(cluster);
//}
}
}
return result;
}
示例5: calculateConditions
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
public List<LongArrayList> calculateConditions(PositionListIndex partialUnique,
PositionListIndex PLICondition,
int frequency,
List<LongArrayList> unsatisfiedClusters) {
List<LongArrayList> result = new LinkedList<>();
Long2LongOpenHashMap uniqueHashMap = partialUnique.asHashMap();
LongArrayList touchedClusters = new LongArrayList();
nextCluster:
for (LongArrayList cluster : PLICondition.getClusters()) {
if (cluster.size() < frequency) {
continue;
}
int unsatisfactionCount = 0;
touchedClusters.clear();
for (long rowNumber : cluster) {
if (uniqueHashMap.containsKey(rowNumber)) {
if (touchedClusters.contains(uniqueHashMap.get(rowNumber))) {
unsatisfactionCount++;
} else {
touchedClusters.add(uniqueHashMap.get(rowNumber));
}
}
}
if (unsatisfactionCount == 0) {
result.add(cluster);
} else {
if ((cluster.size() - unsatisfactionCount) >= frequency) {
unsatisfiedClusters.add(cluster);
}
}
}
return result;
}
示例6: createTransaction
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
/**
* Creates a new Transaction. This method only get called from start transaction, which is already
* synchronized.
*/
private Transaction createTransaction(long writePointer, TransactionType type) {
// For holding the first in progress short transaction Id (with timeout >= 0).
long firstShortTx = Transaction.NO_TX_IN_PROGRESS;
LongArrayList inProgressIds = new LongArrayList(inProgress.size());
for (Map.Entry<Long, InProgressTx> entry : inProgress.entrySet()) {
long txId = entry.getKey();
inProgressIds.add(txId);
if (firstShortTx == Transaction.NO_TX_IN_PROGRESS && !entry.getValue().isLongRunning()) {
firstShortTx = txId;
}
}
return new Transaction(readPointer, writePointer, invalidTxList.toSortedArray(),
inProgressIds.toLongArray(), firstShortTx, type);
}
示例7: decodeInProgress
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
@Override
protected NavigableMap<Long, TransactionManager.InProgressTx> decodeInProgress(BinaryDecoder decoder)
throws IOException {
int size = decoder.readInt();
NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap();
while (size != 0) { // zero denotes end of list as per AVRO spec
for (int remaining = size; remaining > 0; --remaining) {
long txId = decoder.readLong();
long expiration = decoder.readLong();
long visibilityUpperBound = decoder.readLong();
int txTypeIdx = decoder.readInt();
TransactionManager.InProgressType txType;
try {
txType = TransactionManager.InProgressType.values()[txTypeIdx];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Type enum ordinal value is out of range: " + txTypeIdx);
}
// read checkpoint tx IDs
int checkpointPointerSize = decoder.readInt();
LongArrayList checkpointPointers = new LongArrayList(checkpointPointerSize);
while (checkpointPointerSize != 0) {
for (int checkpointRemaining = checkpointPointerSize; checkpointRemaining > 0; --checkpointRemaining) {
checkpointPointers.add(decoder.readLong());
}
checkpointPointerSize = decoder.readInt();
}
inProgress.put(txId,
new TransactionManager.InProgressTx(visibilityUpperBound, expiration, txType, checkpointPointers));
}
size = decoder.readInt();
}
return inProgress;
}
示例8: checkpoint
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
@Override
public Transaction checkpoint(Transaction tx) {
long newWritePointer = getWritePointer();
LongArrayList newCheckpointPointers = new LongArrayList(tx.getCheckpointWritePointers());
newCheckpointPointers.add(newWritePointer);
return new Transaction(tx, newWritePointer, newCheckpointPointers.toLongArray());
}
示例9: combineClusterIntoResult
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
protected void combineClusterIntoResult(ColumnCombinationBitset partialUnique)
throws AlgorithmExecutionException {
LongArrayList touchedCluster = new LongArrayList();
Long2LongOpenHashMap partialUniqueHash = this.algorithm.getPLI(partialUnique).asHashMap();
Set<ColumnCombinationBitset> startPoints = this.getConditionStartPoints();
for (ColumnCombinationBitset minimalConditionStartPoint : startPoints) {
if (minimalConditionStartPoint.getSetBits().size() != 1) {
minimalConditionStartPoint =
minimalConditionStartPoint.getContainedOneColumnCombinations().get(0);
}
List<ConditionEntry> satisfiedCluster = new ArrayList<>();
Long2ObjectOpenHashMap<LongArrayList> intersectingCluster = new Long2ObjectOpenHashMap<>();
int clusterNumber = 0;
//build intersecting cluster
for (ConditionEntry singleCluster : this.singleConditions.get(minimalConditionStartPoint)) {
satisfiedCluster.add(singleCluster.setClusterNumber(clusterNumber));
touchedCluster.clear();
for (long rowNumber : singleCluster.cluster) {
if (partialUniqueHash.containsKey(rowNumber)) {
touchedCluster.add(partialUniqueHash.get(rowNumber));
}
}
for (long partialUniqueClusterNumber : touchedCluster) {
if (intersectingCluster.containsKey(partialUniqueClusterNumber)) {
intersectingCluster.get(partialUniqueClusterNumber).add(clusterNumber);
} else {
LongArrayList newConditionClusterNumbers = new LongArrayList();
newConditionClusterNumbers.add(clusterNumber);
intersectingCluster.put(partialUniqueClusterNumber, newConditionClusterNumbers);
}
}
clusterNumber++;
}
intersectingCluster = purgeIntersectingClusterEntries(intersectingCluster);
//convert into list
List<LongArrayList> intersectingClusterList = new ArrayList<>();
for (long partialUniqueCluster : intersectingCluster.keySet()) {
intersectingClusterList.add(intersectingCluster.get(partialUniqueCluster));
}
Object2FloatArrayMap<List<ConditionEntry>>
clustergroups =
this.combineClusters(this.algorithm.frequency, satisfiedCluster,
intersectingClusterList);
for (List<ConditionEntry> singleCondition : clustergroups.keySet()) {
ResultSingleton.getInstance().addConditionToResult(partialUnique, singleCondition,
clustergroups.get(singleCondition));
}
}
}
示例10: detectNaryViaBucketing
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
private Map<AttributeCombination, List<AttributeCombination>> detectNaryViaBucketing() throws InputGenerationException, InputIterationException, IOException, AlgorithmConfigurationException {
System.out.print("N-ary IND detection ...");
// Clean temp
if (this.cleanTemp)
FileUtils.cleanDirectory(this.tempFolder);
// N-ary column combinations are enumerated following the enumeration of the attributes
int naryOffset = getTotalColumnCount(tables);
// Initialize nPlusOneAryDep2ref with unary dep2ref
Map<AttributeCombination, List<AttributeCombination>> nPlusOneAryDep2ref = new HashMap<>();
for (int dep : this.dep2ref.keySet()) {
AttributeCombination depAttributeCombination = new AttributeCombination(column2table[dep], dep);
List<AttributeCombination> refAttributeCombinations = new LinkedList<>();
ElementIterator refIterator = this.dep2ref.get(dep).elementIterator();
while (refIterator.hasNext()) {
int ref = refIterator.next();
refAttributeCombinations.add(new AttributeCombination(column2table[ref], ref));
}
nPlusOneAryDep2ref.put(depAttributeCombination, refAttributeCombinations);
}
int naryLevel = 1;
// Generate, bucketize and test the n-ary INDs level-wise
LongArrayList naryGenerationTime = new LongArrayList();
LongArrayList naryCompareTime = new LongArrayList();
while (++naryLevel <= this.maxNaryLevel || this.maxNaryLevel <= 0) {
System.out.print(" L" + naryLevel);
// Generate (n+1)-ary IND candidates from the already identified unary and n-ary IND candidates
final long naryGenerationTimeCurrent = System.currentTimeMillis();
Map<AttributeCombination, List<AttributeCombination>> naryDep2ref = nPlusOneAryDep2ref;
nPlusOneAryDep2ref = this.generateNPlusOneAryCandidates(nPlusOneAryDep2ref, bucketMetadata.getColumnSizes());
if (nPlusOneAryDep2ref.isEmpty()) {
nPlusOneAryDep2ref = naryDep2ref;
naryLevel -= 1;
break;
}
// Collect all attribute combinations of the current level that are possible refs or deps and enumerate them
Set<AttributeCombination> attributeCombinationSet = new HashSet<>();
attributeCombinationSet.addAll(nPlusOneAryDep2ref.keySet());
nPlusOneAryDep2ref.values().forEach(attributeCombinationSet::addAll);
List<AttributeCombination> attributeCombinations = new ArrayList<>(attributeCombinationSet);
// Extend the columnSize array
LongArrayList columnSizes = bucketMetadata.getColumnSizes();
for (int i = 0; i < attributeCombinations.size(); i++)
columnSizes.add(0);
bucketMetadata.setColumnSizes(columnSizes);
int[] currentNarySpillCounts = new int[attributeCombinations.size()];
for (int attributeCombinationNumber = 0; attributeCombinationNumber < attributeCombinations.size(); attributeCombinationNumber++)
currentNarySpillCounts[attributeCombinationNumber] = 0;
naryGenerationTime.add(System.currentTimeMillis() - naryGenerationTimeCurrent);
// Read the input dataset again and bucketize all attribute combinations that are refs or deps
int[] bucketComparisonOrder = this.naryBucketize(attributeCombinations, naryOffset, currentNarySpillCounts);
bucketMetadata.setBucketComparisonOrder(bucketComparisonOrder);
// Check the n-ary IND candidates
long naryCompareTimeCurrent = System.currentTimeMillis();
nPlusOneAryDep2ref = this.naryCheckViaTwoStageIndexAndLists(nPlusOneAryDep2ref, attributeCombinations, naryOffset);
// Add the number of created buckets for n-ary INDs of this level to the naryOffset
naryOffset = naryOffset + attributeCombinations.size();
naryCompareTime.add(System.currentTimeMillis() - naryCompareTimeCurrent);
System.out.print("(" + (System.currentTimeMillis() - naryGenerationTimeCurrent) + " ms)");
}
return nPlusOneAryDep2ref;
}
示例11: createRandomSnapshot
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
/**
* Generates a new snapshot object with semi-randomly populated values. This does not necessarily accurately
* represent a typical snapshot's distribution of values, as we only set an upper bound on pointer values.
*
* We generate a new snapshot with the contents:
* <ul>
* <li>readPointer = 1M + (random % 1M)</li>
* <li>writePointer = readPointer + 1000</li>
* <li>waterMark = writePointer + 1000</li>
* <li>inProgress = one each for (writePointer - 500)..writePointer, ~ 5% "long" transaction</li>
* <li>invalid = 100 randomly distributed, 0..1M</li>
* <li>committing = one each, (readPointer + 1)..(readPointer + 100)</li>
* <li>committed = one each, (readPointer - 1000)..readPointer</li>
* </ul>
* @return a new snapshot of transaction state.
*/
private TransactionSnapshot createRandomSnapshot() {
// limit readPointer to a reasonable range, but make it > 1M so we can assign enough keys below
long readPointer = (Math.abs(random.nextLong()) % 1000000L) + 1000000L;
long writePointer = readPointer + 1000L;
// generate in progress -- assume last 500 write pointer values
NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap();
long startPointer = writePointer - 500L;
for (int i = 0; i < 500; i++) {
long currentTime = System.currentTimeMillis();
// make some "long" transactions
if (i % 20 == 0) {
inProgress.put(startPointer + i,
new TransactionManager.InProgressTx(startPointer - 1, currentTime + TimeUnit.DAYS.toSeconds(1),
TransactionManager.InProgressType.LONG));
} else {
inProgress.put(startPointer + i,
new TransactionManager.InProgressTx(startPointer - 1, currentTime + 300000L,
TransactionManager.InProgressType.SHORT));
}
}
// make 100 random invalid IDs
LongArrayList invalid = new LongArrayList();
for (int i = 0; i < 100; i++) {
invalid.add(Math.abs(random.nextLong()) % 1000000L);
}
// make 100 committing entries, 10 keys each
Map<Long, Set<ChangeId>> committing = Maps.newHashMap();
for (int i = 0; i < 100; i++) {
committing.put(readPointer + i, generateChangeSet(10));
}
// make 1000 committed entries, 10 keys each
long startCommitted = readPointer - 1000L;
NavigableMap<Long, Set<ChangeId>> committed = Maps.newTreeMap();
for (int i = 0; i < 1000; i++) {
committed.put(startCommitted + i, generateChangeSet(10));
}
return new TransactionSnapshot(System.currentTimeMillis(), readPointer, writePointer,
invalid, inProgress, committing, committed);
}
示例12: main
import it.unimi.dsi.fastutil.longs.LongArrayList; //导入方法依赖的package包/类
public static void main(final String[] arg) throws JSAPException {
final SimpleJSAP jsap = new SimpleJSAP(TwoSizesLongBigListSpeedTest.class.getName(), "Tests the speed of rank/select implementations.",
new Parameter[] {
new UnflaggedOption("numElements", JSAP.INTSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The number of elements."),
new UnflaggedOption("density", JSAP.DOUBLE_PARSER, ".5", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The density."),
new FlaggedOption("numPos", JSAP.INTSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, 'p', "positions", "The number of positions to test"),
});
final JSAPResult jsapResult = jsap.parse(arg);
if (jsap.messagePrinted()) return;
final int numElements = jsapResult.getInt("numElements");
final double density = jsapResult.getDouble("density");
final int numPos = jsapResult.getInt("numPos");
final XoRoShiRo128PlusRandomGenerator random = new XoRoShiRo128PlusRandomGenerator(0);
final LongArrayList list = new LongArrayList(numElements);
for(long i = numElements; i-- != 0;) list.add(random.nextDouble() < density ? 0 : 100);
final int[] position = new int[numPos];
for(int i = numPos; i-- != 0;) position[i] = (random.nextInt() & 0x7FFFFFFF) % numElements;
final TwoSizesLongBigList twoSizes = new TwoSizesLongBigList(list);
final EliasFanoLongBigList eliasFano = new EliasFanoLongBigList(list);
final EliasFanoPrefixSumLongBigList eliasFanoPrefixSum = new EliasFanoPrefixSumLongBigList(list);
final long[] elements = list.elements();
for(int i = 1; i < list.size(); i++) elements[i] += elements[i - 1];
final EliasFanoMonotoneLongBigList monotone = new EliasFanoMonotoneLongBigList(list);
final EliasFanoMonotoneLongBigListTables tables = new EliasFanoMonotoneLongBigListTables(list);
long time;
for(int k = 10; k-- != 0;) {
System.out.println("=== LongArrayList === (" + list.size() * (long)Long.SIZE + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) list.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
System.out.println("=== TwoSizesLongBigList === (" + twoSizes.numBits() + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) twoSizes.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
System.out.println("=== EliasFanoPrefixSumLongBigList === (" + eliasFanoPrefixSum.numBits() + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) eliasFanoPrefixSum.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
System.out.println("=== EliasFanoLongBigList === (" + eliasFano.numBits() + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) eliasFano.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
System.out.println("=== EliasFanoMonotoneLongBigListTables === (" + tables.numBits() + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) tables.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
System.out.println("=== EliasFanoMonotoneLongBigList === (" + monotone.numBits() + " bits)");
time = - System.nanoTime();
for(int i = 0; i < numPos; i++) monotone.getLong(position[i]);
time += System.nanoTime();
System.err.println(time / 1E9 + "s, " + (double)time / numPos + " ns/get");
}
}