• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Hash类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.solr.common.util.Hash的典型用法代码示例。如果您正苦于以下问题:Java Hash类的具体用法?Java Hash怎么用?Java Hash使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Hash类属于org.apache.solr.common.util包,在下文中一共展示了Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: chooseTasks

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
public List<Integer> chooseTasks(int taskId, List<Object> values) {
  if (values == null || values.size() < 1)
    return Collections.singletonList(targetTasks.get(0));

  String docId = (String) values.get(0);
  if (docId == null)
    return Collections.singletonList(targetTasks.get(0));


  final int hash = Hash.murmurhash3_x86_32(docId, 0, docId.length(), 0);
  int rangeIndex = 0;
  for (int r=0; r < ranges.size(); r++) {
    if (ranges.get(r).includes(hash)) {
      rangeIndex = r;
      break;
    }
  }
  int selectedTask = (tasksPerShard > 1) ? rangeIndex + (random.sample() * tasksPerShard) : rangeIndex;
  return Collections.singletonList(targetTasks.get(selectedTask));
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:21,代码来源:HashRangeGrouping.java


示例2: getSearchSlicesSingle

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) {
  if (shardKey == null) {
    // search across whole collection
    // TODO: this may need modification in the future when shard splitting could cause an overlap
    return collection.getActiveSlices();
  }
  String id = shardKey;

  if (shardKey.indexOf(SEPARATOR) < 0) {
    // shardKey is a simple id, so don't do a range
    return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection));
  }

  Range completeRange = new KeyParser(id).getRange();

  List<Slice> targetSlices = new ArrayList<>(1);
  for (Slice slice : collection.getActiveSlices()) {
    Range range = slice.getRange();
    if (range != null && range.overlaps(completeRange)) {
      targetSlices.add(slice);
    }
  }

  return targetSlices;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:CompositeIdRouter.java


示例3: getRanges

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
private List<DocRouter.Range> getRanges(String id1, String id2) throws UnsupportedEncodingException {
  // find minHash/maxHash hash ranges
  byte[] bytes = id1.getBytes(StandardCharsets.UTF_8);
  int minHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);
  bytes = id2.getBytes(StandardCharsets.UTF_8);
  int maxHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);

  if (minHash > maxHash)  {
    int temp = maxHash;
    maxHash = minHash;
    minHash = temp;
  }

  PlainIdRouter router = new PlainIdRouter();
  DocRouter.Range fullRange = new DocRouter.Range(minHash, maxHash);
  return router.partitionRange(2, fullRange);
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:SolrIndexSplitterTest.java


示例4: getSearchSlicesSingle

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) {
  if (shardKey == null) {
    // search across whole collection
    // TODO: this may need modification in the future when shard splitting could cause an overlap
    return collection.getActiveSlices();
  }
  String id = shardKey;

  if (shardKey.indexOf(SEPARATOR) < 0) {
    // shardKey is a simple id, so don't do a range
    return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection));
  }

  Range completeRange = new KeyParser(id).getRange();

  List<Slice> targetSlices = new ArrayList<Slice>(1);
  for (Slice slice : collection.getActiveSlices()) {
    Range range = slice.getRange();
    if (range != null && range.overlaps(completeRange)) {
      targetSlices.add(slice);
    }
  }

  return targetSlices;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:27,代码来源:CompositeIdRouter.java


示例5: sliceHash

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
public int sliceHash(String id, SolrInputDocument doc, SolrParams params, DocCollection collection) {
  String shardFieldName = getRouteField(collection);
  if (shardFieldName != null && doc != null) {
    Object o = doc.getFieldValue(shardFieldName);
    if (o == null)
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No value for :" + shardFieldName + ". Unable to identify shard");
    id = o.toString();
  }
  if (id.indexOf(SEPARATOR) < 0) {
    return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
  }

  return new KeyParser(id).getHash();
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:CompositeIdRouter.java


示例6: sliceHash

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
protected int sliceHash(String id, SolrInputDocument doc, SolrParams params) {
  int idx = id.indexOf(separator);
  if (idx < 0) {
    return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
  }

  int m1 = mask1;
  int m2 = mask2;

  String part1 = id.substring(0,idx);
  int commaIdx = part1.indexOf(bitsSepartor);
  if (commaIdx > 0) {
    int firstBits = getBits(part1, commaIdx);
    if (firstBits >= 0) {
      m1 = firstBits==0 ? 0 : (-1 << (32-firstBits));
      m2 = firstBits==32 ? 0 : (-1 >>> firstBits);
      part1 = part1.substring(0, commaIdx);
    }
  }

  String part2 = id.substring(idx+1);

  int hash1 = Hash.murmurhash3_x86_32(part1, 0, part1.length(), 0);
  int hash2 = Hash.murmurhash3_x86_32(part2, 0, part2.length(), 0);
  return (hash1 & m1) | (hash2 & m2);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:28,代码来源:CompositeIdRouter.java


示例7: split

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
OpenBitSet[] split(AtomicReaderContext readerContext) throws IOException {
  AtomicReader reader = readerContext.reader();
  OpenBitSet[] docSets = new OpenBitSet[ranges.size()];
  for (int i=0; i<docSets.length; i++) {
    docSets[i] = new OpenBitSet(reader.maxDoc());
  }
  Bits liveDocs = reader.getLiveDocs();

  Fields fields = reader.fields();
  Terms terms = fields==null ? null : fields.terms(field.getName());
  TermsEnum termsEnum = terms==null ? null : terms.iterator(null);
  if (termsEnum == null) return docSets;

  BytesRef term = null;
  DocsEnum docsEnum = null;

  for (;;) {
    term = termsEnum.next();
    if (term == null) break;

    // figure out the hash for the term
    // TODO: hook in custom hashes (or store hashes)
    int hash = Hash.murmurhash3_x86_32(term.bytes, term.offset, term.length, 0);

    docsEnum = termsEnum.docs(liveDocs, docsEnum, DocsEnum.FLAG_NONE);
    for (;;) {
      int doc = docsEnum.nextDoc();
      if (doc == DocsEnum.NO_MORE_DOCS) break;
      for (int i=0; i<rangesArr.length; i++) {      // inner-loop: use array here for extra speed.
        if (rangesArr[i].includes(hash)) {
          docSets[i].fastSet(doc);
        }
      }
    }
  }

  return docSets;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:39,代码来源:SolrIndexSplitter.java


示例8: getRanges

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
private List<DocRouter.Range> getRanges(String id1, String id2) throws UnsupportedEncodingException {
  // find minHash/maxHash hash ranges
  byte[] bytes = id1.getBytes("UTF-8");
  int minHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);
  bytes = id2.getBytes("UTF-8");
  int maxHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);

  PlainIdRouter router = new PlainIdRouter();
  DocRouter.Range fullRange = new DocRouter.Range(minHash, maxHash);
  return router.partitionRange(2, fullRange);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:12,代码来源:SolrIndexSplitterTest.java


示例9: KeyParser

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
public KeyParser(String key) {
  String[] parts = key.split(SEPARATOR);
  this.key = key;
  pieces = parts.length;
  numBits = new int[2];
  if (key.endsWith("!") && pieces < 3)
    pieces++;
  hashes = new int[pieces];

  if (pieces == 3) {
    numBits[0] = 8;
    numBits[1] = 8;
    triLevel = true;
  } else {
    numBits[0] = 16;
    triLevel = false;
  }

  for (int i = 0; i < pieces; i++) {
    if (i < pieces - 1) {
      int commaIdx = parts[i].indexOf(bitsSeparator);

      if (commaIdx > 0) {
        numBits[i] = getNumBits(parts[i], commaIdx);
        parts[i] = parts[i].substring(0, commaIdx);
      }
    }
    //Last component of an ID that ends with a '!'
    if(i >= parts.length)
      hashes[i] = Hash.murmurhash3_x86_32("", 0, "".length(), 0);
    else
      hashes[i] = Hash.murmurhash3_x86_32(parts[i], 0, parts[i].length(), 0);
  }
  masks = getMasks();
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:36,代码来源:CompositeIdRouter.java


示例10: sliceHash

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
public int sliceHash(String id, SolrInputDocument sdoc, SolrParams params, DocCollection collection) {
  return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:HashBasedRouter.java


示例11: KeyParser

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
public KeyParser(final String key) {
  this.key = key;
  List<String> partsList = new ArrayList<>(3);
  int firstSeparatorPos = key.indexOf(SEPARATOR);
  if (-1 == firstSeparatorPos) {
    partsList.add(key);
  } else {
    partsList.add(key.substring(0, firstSeparatorPos));
    int lastPos = key.length() - 1;
    // Don't make any more parts if the first separator is the last char
    if (firstSeparatorPos < lastPos) {
      int secondSeparatorPos = key.indexOf(SEPARATOR, firstSeparatorPos + 1);
      if (-1 == secondSeparatorPos) {
        partsList.add(key.substring(firstSeparatorPos + 1));
      } else if (secondSeparatorPos == lastPos) {
        // Don't make any more parts if the key has exactly two separators and 
        // they're the last two chars - back-compatibility with the behavior of
        // String.split() - see SOLR-6257.
        if (firstSeparatorPos < secondSeparatorPos - 1) {
          partsList.add(key.substring(firstSeparatorPos + 1, secondSeparatorPos));
        }
      } else { // The second separator is not the last char
        partsList.add(key.substring(firstSeparatorPos + 1, secondSeparatorPos));
        partsList.add(key.substring(secondSeparatorPos + 1));
      }
      // Ignore any further separators beyond the first two
    }
  }
  pieces = partsList.size();
  String[] parts = partsList.toArray(new String[pieces]);
  numBits = new int[2];
  if (key.endsWith("!") && pieces < 3)
    pieces++;
  hashes = new int[pieces];

  if (pieces == 3) {
    numBits[0] = 8;
    numBits[1] = 8;
    triLevel = true;
  } else {
    numBits[0] = 16;
    triLevel = false;
  }

  for (int i = 0; i < pieces; i++) {
    if (i < pieces - 1) {
      int commaIdx = parts[i].indexOf(bitsSeparator);

      if (commaIdx > 0) {
        numBits[i] = getNumBits(parts[i], commaIdx);
        parts[i] = parts[i].substring(0, commaIdx);
      }
    }
    //Last component of an ID that ends with a '!'
    if(i >= parts.length)
      hashes[i] = Hash.murmurhash3_x86_32("", 0, "".length(), 0);
    else
      hashes[i] = Hash.murmurhash3_x86_32(parts[i], 0, parts[i].length(), 0);
  }
  masks = getMasks();
}
 
开发者ID:europeana,项目名称:search,代码行数:62,代码来源:CompositeIdRouter.java


示例12: add

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
public void add(String content) {
  hash = Hash.lookup3ycs64(content,0,content.length(),hash);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:Lookup3Signature.java


示例13: hash

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
public int hash(String id) {
  // our hashing is defined to be murmurhash3 on the UTF-8 bytes of the key.
  return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:TestHashPartitioner.java


示例14: sliceHash

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
protected int sliceHash(String id, SolrInputDocument sdoc, SolrParams params) {
  return Hash.murmurhash3_x86_32(id, 0, id.length(), 0);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:4,代码来源:HashBasedRouter.java


示例15: getSearchSlicesSingle

import org.apache.solr.common.util.Hash; //导入依赖的package包/类
@Override
public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) {
  if (shardKey == null) {
    // search across whole collection
    // TODO: this may need modification in the future when shard splitting could cause an overlap
    return collection.getSlices();
  }
  String id = shardKey;

  int idx = shardKey.indexOf(separator);
  if (idx < 0) {
    // shardKey is a simple id, so don't do a range
    return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection));
  }

  int m1 = mask1;
  int m2 = mask2;

  String part1 = id.substring(0,idx);
  int bitsSepIdx = part1.indexOf(bitsSepartor);
  if (bitsSepIdx > 0) {
    int firstBits = getBits(part1, bitsSepIdx);
    if (firstBits >= 0) {
      m1 = firstBits==0 ? 0 : (-1 << (32-firstBits));
      m2 = firstBits==32 ? 0 : (-1 >>> firstBits);
      part1 = part1.substring(0, bitsSepIdx);
    }
  }

  //  If the upper bits are 0xF0000000, the range we want to cover is
  //  0xF0000000 0xFfffffff

  int hash1 = Hash.murmurhash3_x86_32(part1, 0, part1.length(), 0);
  int upperBits = hash1 & m1;
  int lowerBound = upperBits;
  int upperBound = upperBits | m2;

  if (m1 == 0) {
    // no bits used from first part of key.. the code above will produce 0x000000000->0xffffffff which only works on unsigned space, but we're using signed space.
    lowerBound = Integer.MIN_VALUE;
    upperBound = Integer.MAX_VALUE;
  }

  Range completeRange = new Range(lowerBound, upperBound);

  List<Slice> targetSlices = new ArrayList<Slice>(1);
  for (Slice slice : collection.getSlices()) {
    Range range = slice.getRange();
    if (range != null && range.overlaps(completeRange)) {
      targetSlices.add(slice);
    }
  }

  return targetSlices;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:56,代码来源:CompositeIdRouter.java



注:本文中的org.apache.solr.common.util.Hash类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ParsedValue类代码示例发布时间:2022-05-23
下一篇:
Java TvInputInfo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap