@Override public boolean positionEqualsPosition(int leftBlockIndex, int leftPosition, int rightBlockIndex, int rightPosition) { for (int hashChannel : hashChannels) { Type type = types.get(hashChannel); List<Block> channel = channels.get(hashChannel); Block leftBlock = channel.get(leftBlockIndex); Block rightBlock = channel.get(rightBlockIndex); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
@Override public boolean positionEqualsRow(int leftBlockIndex, int leftPosition, int rightPosition, Page page, int[] rightHashChannels) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = channels.get(hashChannel).get(leftBlockIndex); Block rightBlock = page.getBlock(rightHashChannels[i]); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
@Override public boolean positionEqualsRow(int leftBlockIndex, int leftPosition, int rightPosition, Page rightPage) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = channels.get(hashChannel).get(leftBlockIndex); Block rightBlock = rightPage.getBlock(i); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
@Override public boolean rowEqualsRow(int leftPosition, Page leftPage, int rightPosition, Page rightPage) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = leftPage.getBlock(i); Block rightBlock = rightPage.getBlock(i); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
private int getHashPosition(int position) { int hashPosition = getMaskedHash(hashPosition(type, block, position)); while (true) { if (positionByHash[hashPosition] == EMPTY_SLOT) { return hashPosition; } else if (positionEqualsPosition(type, block, positionByHash[hashPosition], block, position)) { return hashPosition; } hashPosition = getMaskedHash(hashPosition + 1); } }
private int getHashPositionOfKey(Block key, int position) { int hashPosition = getMaskedHash(hashPosition(keyType, key, position)); while (true) { if (keyPositionByHash[hashPosition] == EMPTY_SLOT) { return hashPosition; } else if (positionEqualsPosition(keyType, keyBlockBuilder, keyPositionByHash[hashPosition], key, position)) { return hashPosition; } hashPosition = getMaskedHash(hashPosition + 1); } }
/** * Get slot position of element at {@code position} of {@code block} */ private int getHashPositionOfElement(Block block, int position) { int hashPosition = getMaskedHash(hashPosition(elementType, block, position)); while (true) { int blockPosition = blockPositionByHash.get(hashPosition); // Doesn't have this element if (blockPosition == EMPTY_SLOT) { return hashPosition; } // Already has this element else if (positionEqualsPosition(elementType, elementBlock, blockPosition, block, position)) { return hashPosition; } hashPosition = getMaskedHash(hashPosition + 1); } }
Block rightBlock = channel.get(rightBlockIndex); for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) { boolean expected = positionEqualsPosition(VARCHAR, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected); assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expected); Block rightBlock = channel.get(rightBlockIndex); for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) { boolean expected = positionEqualsPosition(VARCHAR, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected); assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expected);
assertTrue(positionEqualsPosition(type, block, position, block, position)); assertTrue(positionEqualsPosition(type, block, position, expectedBlock, 0)); assertTrue(positionEqualsPosition(type, expectedBlock, 0, block, position));
if (TypeUtils.positionEqualsPosition(type, array, 0, array, 1)) { return array.getSingleValueBlock(0);
@Override public boolean rowEqualsRow(int leftPosition, Block[] leftBlocks, int rightPosition, Block[] rightBlocks) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = leftBlocks[i]; Block rightBlock = rightBlocks[i]; if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
@Override public boolean positionEqualsRow(int leftBlockIndex, int leftPosition, int rightPosition, Block... rightBlocks) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = channels.get(hashChannel).get(leftBlockIndex); Block rightBlock = rightBlocks[i]; if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
@Override public boolean positionEqualsPosition(int leftBlockIndex, int leftPosition, int rightBlockIndex, int rightPosition) { for (int hashChannel : hashChannels) { Type type = types.get(hashChannel); List<Block> channel = channels.get(hashChannel); Block leftBlock = channel.get(leftBlockIndex); Block rightBlock = channel.get(rightBlockIndex); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; } }
@Override public boolean positionEqualsRow(int leftBlockIndex, int leftPosition, int rightPosition, Page page, int[] rightChannels) { for (int i = 0; i < hashChannels.size(); i++) { int hashChannel = hashChannels.get(i); Type type = types.get(hashChannel); Block leftBlock = channels.get(hashChannel).get(leftBlockIndex); Block rightBlock = page.getBlock(rightChannels[i]); if (!TypeUtils.positionEqualsPosition(type, leftBlock, leftPosition, rightBlock, rightPosition)) { return false; } } return true; }
/** * Get slot position of element at {@code position} of {@code block} */ private int getHashPositionOfElement(Block block, int position) { int hashPosition = getMaskedHash(hashPosition(elementType, block, position)); while (true) { int blockPosition = blockPositionByHash.get(hashPosition); // Doesn't have this element if (blockPosition == EMPTY_SLOT) { return hashPosition; } // Already has this element else if (positionEqualsPosition(elementType, elementBlock, blockPosition, block, position)) { return hashPosition; } hashPosition = getMaskedHash(hashPosition + 1); } }
Block rightBlock = channel.get(rightBlockIndex); for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) { boolean expected = positionEqualsPosition(VARCHAR, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, rightBlock), expected); assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Block[] {leftBlock}, rightBlockPosition, new Block[] {rightBlock}), expected); Block rightBlock = channel.get(rightBlockIndex); for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) { boolean expected = positionEqualsPosition(VARCHAR, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition); assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, rightBlock), expected); assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Block[] {leftBlock}, rightBlockPosition, new Block[] {rightBlock}), expected);
assertTrue(positionEqualsPosition(type, block, position, block, position)); assertTrue(positionEqualsPosition(type, block, position, expectedBlock, 0)); assertTrue(positionEqualsPosition(type, expectedBlock, 0, block, position));