Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.facebook.presto.operator.scalar;
 /*
  * 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.
 */
import static com.facebook.presto.metadata.FunctionRegistry.operatorInfo;
import static com.facebook.presto.metadata.OperatorType.HASH_CODE;
import static com.facebook.presto.metadata.Signature.comparableTypeParameter;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static com.facebook.presto.type.TypeUtils.hashPosition;
import static com.facebook.presto.type.TypeUtils.readStructuralBlock;
import static com.facebook.presto.util.Reflection.methodHandle;
public class MapHashCodeOperator
        extends ParametricOperator
    public static final MapHashCodeOperator MAP_HASH_CODE = new MapHashCodeOperator();
    private static final TypeSignature RETURN_TYPE = parseTypeSignature(.);
    private MapHashCodeOperator()
    {
        super(, ImmutableList.of(comparableTypeParameter("K"), comparableTypeParameter("V")), ., ImmutableList.of("map<K,V>"));
    }
    @Override
    public FunctionInfo specialize(Map<StringTypetypesint arityTypeManager typeManagerFunctionRegistry functionRegistry)
    {
        Type keyType = types.get("K");
        Type valueType = types.get("V");
        Type type = typeManager.getParameterizedType(., ImmutableList.of(keyType.getTypeSignature(), valueType.getTypeSignature()), ImmutableList.of());
        TypeSignature typeSignature = type.getTypeSignature();
        MethodHandle keyHashCodeFunction = functionRegistry.resolveOperator(, ImmutableList.of(keyType)).getMethodHandle();
        MethodHandle valueHashCodeFunction = functionRegistry.resolveOperator(, ImmutableList.of(valueType)).getMethodHandle();
        MethodHandle methodHandle = methodHandle(MapHashCodeOperator.class"hash"MethodHandle.classMethodHandle.classType.classType.classSlice.class);
        MethodHandle method = methodHandle.bindTo(keyHashCodeFunction).bindTo(valueHashCodeFunction).bindTo(keyType).bindTo(valueType);
        return operatorInfo(, ImmutableList.of(typeSignature), methodfalse, ImmutableList.of(false));
    }
    public static long hash(MethodHandle keyHashCodeFunctionMethodHandle valueHashCodeFunctionType keyTypeType valueTypeSlice slice)
    {
        Block block = readStructuralBlock(slice);
        long result = 0;
        for (int position = 0; position < block.getPositionCount(); position += 2) {
            result += hashPosition(keyHashCodeFunctionkeyTypeblockposition);
            result += hashPosition(valueHashCodeFunctionvalueTypeblockposition + 1);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X