Example usage for org.apache.spark.unsafe.array LongArray size

List of usage examples for org.apache.spark.unsafe.array LongArray size

Introduction

In this page you can find the example usage for org.apache.spark.unsafe.array LongArray size.

Prototype

public long size() 

Source Link

Document

Returns the number of elements this array can hold.

Usage

From source file:edu.ucla.cs.wis.bigdatalog.spark.storage.map.BytesToBytesMap.java

License:Apache License

/**
 * Grows the size of the hash table and re-hash everything.
 *//*  ww  w .  j  ava2  s  .c om*/
@VisibleForTesting
void growAndRehash() {
    assert (longArray != null);

    long resizeStartTime = -1;
    if (enablePerfMetrics) {
        resizeStartTime = System.nanoTime();
    }
    // Store references to the old data structures to be used when we re-hash
    final LongArray oldLongArray = longArray;
    final int oldCapacity = (int) oldLongArray.size() / 2;

    // Allocate the new data structures
    allocate(Math.min(growthStrategy.nextCapacity(oldCapacity), MAX_CAPACITY));

    // Re-mask (we don't recompute the hashcode because we stored all 32 bits of it)
    for (int i = 0; i < oldLongArray.size(); i += 2) {
        final long keyPointer = oldLongArray.get(i);
        if (keyPointer == 0) {
            continue;
        }
        final int hashcode = (int) oldLongArray.get(i + 1);
        int newPos = hashcode & mask;
        int step = 1;
        while (longArray.get(newPos * 2) != 0) {
            newPos = (newPos + step) & mask;
            step++;
        }
        longArray.set(newPos * 2, keyPointer);
        longArray.set(newPos * 2 + 1, hashcode);
    }
    freeArray(oldLongArray);

    if (enablePerfMetrics) {
        timeSpentResizingNs += System.nanoTime() - resizeStartTime;
    }
}