@Override public final long getJoinPosition(BlockCursor... cursors) { int pos = ((int) Murmur3.hash64(hashCursor(cursors))) & mask; while (key[pos] != -1) { if (positionEqualsCurrentRow(key[pos], cursors)) { return key[pos]; } // increment position and mask to handler wrap around pos = (pos + 1) & mask; } return -1; }
public InMemoryJoinHash( LongArrayList addresses, PagesHashStrategy pagesHashStrategy, OperatorContext operatorContext) { this.addresses = checkNotNull(addresses, "addresses is null"); this.pagesHashStrategy = checkNotNull(pagesHashStrategy, "pagesHashStrategy is null"); this.channelCount = pagesHashStrategy.getChannelCount(); checkNotNull(operatorContext, "operatorContext is null"); // reserve memory for the arrays int hashSize = HashCommon.arraySize(addresses.size(), 0.75f); operatorContext.reserveMemory(sizeOfIntArray(hashSize) + sizeOfIntArray(addresses.size())); mask = hashSize - 1; key = new int[hashSize]; Arrays.fill(key, -1); this.positionLinks = new int[addresses.size()]; Arrays.fill(positionLinks, -1); // index pages for (int position = 0; position < addresses.size(); position++) { int pos = ((int) Murmur3.hash64(hashPosition(position))) & mask; // look for an empty slot or a slot containing this key while (key[pos] != -1) { int currentKey = key[pos]; if (positionEqualsPosition(currentKey, position)) { // found a slot for this key // link the new key position to the current key position positionLinks[position] = currentKey; // key[pos] updated outside of this loop break; } // increment position and mask to handler wrap around pos = (pos + 1) & mask; } key[pos] = position; } }