mapreduce 中partioner 哈希算法

 

public int getPartition(K key, V value, int numReduceTasks) {
     return (key.hashCode() & Integer.MAX_VALUE) % numReduceTasks;
}

 

 

java String 的hashCode:

public int hashCode() {
    int h = hash;
    if (h == 0 && value.length > 0) {
        char val[] = value;

        for (int i = 0; i < value.length; i++) {
            h = 31 * h + val[i];
        }
        hash = h;
    }
    return h;
}                

  

 

posted on 2019-06-26 20:47  不忘初衷,方能致远  阅读(507)  评论(0编辑  收藏  举报

导航