Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.operator;
 
 
 import java.util.List;
 
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class SimplePagesHashStrategy
         implements PagesHashStrategy
 {
     private final List<Typetypes;
     private final List<List<Block>> channels;
     private final List<IntegerhashChannels;
     private final List<BlockprecomputedHashChannel;
 
     public SimplePagesHashStrategy(List<TypetypesList<List<Block>> channelsList<IntegerhashChannelsOptional<IntegerprecomputedHashChannel)
     {
         this. = ImmutableList.copyOf(checkNotNull(types"types is null"));
         this. = ImmutableList.copyOf(checkNotNull(channels"channels is null"));
         checkArgument(types.size() == channels.size(), "Expected types and channels to be the same length");
         this. = ImmutableList.copyOf(checkNotNull(hashChannels"hashChannels is null"));
         if (precomputedHashChannel.isPresent()) {
             this. = channels.get(precomputedHashChannel.get());
         }
         else {
             this. = null;
         }
     }
 
     @Override
     public int getChannelCount()
     {
         return .size();
     }
 
     @Override
     public void appendTo(int blockIndexint positionPageBuilder pageBuilderint outputChannelOffset)
     {
         for (int i = 0; i < .size(); i++) {
             Type type = .get(i);
             List<Blockchannel = .get(i);
             Block block = channel.get(blockIndex);
             type.appendTo(blockpositionpageBuilder.getBlockBuilder(outputChannelOffset));
             outputChannelOffset++;
         }
     }
 
     @Override
     public int hashPosition(int blockIndexint position)
     {
         if ( != null) {
             return (int.getLong(.get(blockIndex), position);
         }
         int result = 0;
         for (int hashChannel : ) {
             Type type = .get(hashChannel);
             Block block = .get(hashChannel).get(blockIndex);
             result = result * 31 + TypeUtils.hashPosition(typeblockposition);
         }
         return result;
     }
 
     @Override
     public int hashRow(int positionBlock... blocks)
     {
         int result = 0;
         for (int i = 0; i < .size(); i++) {
             int hashChannel = .get(i);
             Type type = .get(hashChannel);
             Block block = blocks[i];
             result = result * 31 + TypeUtils.hashPosition(typeblockposition);
         }
         return result;
     }
 
     @Override
     public boolean positionEqualsRow(int leftBlockIndexint leftPositionint rightPositionBlock... rightBlocks)
     {
        for (int i = 0; i < .size(); i++) {
            int hashChannel = .get(i);
            Type type = .get(hashChannel);
            Block leftBlock = .get(hashChannel).get(leftBlockIndex);
            Block rightBlock = rightBlocks[i];
            if (!TypeUtils.positionEqualsPosition(typeleftBlockleftPositionrightBlockrightPosition)) {
                return false;
            }
        }
        return true;
    }
    @Override
    public boolean positionEqualsPosition(int leftBlockIndexint leftPositionint rightBlockIndexint rightPosition)
    {
        for (int hashChannel : ) {
            Type type = .get(hashChannel);
            List<Blockchannel = .get(hashChannel);
            Block leftBlock = channel.get(leftBlockIndex);
            Block rightBlock = channel.get(rightBlockIndex);
            if (!TypeUtils.positionEqualsPosition(typeleftBlockleftPositionrightBlockrightPosition)) {
                return false;
            }
        }
        return true;
    }
New to GrepCode? Check out our FAQ X