コード例 #1
0
ファイル: InMemoryJoinHash.java プロジェクト: jzmq/presto
  private boolean positionEqualsPosition(int leftPosition, int rightPosition) {
    long leftPageAddress = addresses.getLong(leftPosition);
    int leftBlockIndex = decodeSliceIndex(leftPageAddress);
    int leftBlockPosition = decodePosition(leftPageAddress);

    long rightPageAddress = addresses.getLong(rightPosition);
    int rightBlockIndex = decodeSliceIndex(rightPageAddress);
    int rightBlockPosition = decodePosition(rightPageAddress);

    return pagesHashStrategy.positionEqualsPosition(
        leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition);
  }
コード例 #2
0
ファイル: InMemoryJoinHash.java プロジェクト: jzmq/presto
  private boolean positionEqualsCurrentRow(int position, BlockCursor... cursors) {
    long pageAddress = addresses.getLong(position);
    int blockIndex = decodeSliceIndex(pageAddress);
    int blockPosition = decodePosition(pageAddress);

    return pagesHashStrategy.positionEqualsCursors(blockIndex, blockPosition, cursors);
  }
コード例 #3
0
ファイル: InMemoryJoinHash.java プロジェクト: jzmq/presto
  private int hashPosition(int position) {
    long pageAddress = addresses.getLong(position);
    int blockIndex = decodeSliceIndex(pageAddress);
    int blockPosition = decodePosition(pageAddress);

    return pagesHashStrategy.hashPosition(blockIndex, blockPosition);
  }
コード例 #4
0
ファイル: InMemoryJoinHash.java プロジェクト: jzmq/presto
  public void appendTo(long position, PageBuilder pageBuilder, int outputChannelOffset) {
    long pageAddress = addresses.getLong(Ints.checkedCast(position));
    int blockIndex = decodeSliceIndex(pageAddress);
    int blockPosition = decodePosition(pageAddress);

    pagesHashStrategy.appendTo(blockIndex, blockPosition, pageBuilder, outputChannelOffset);
  }
コード例 #5
0
ファイル: InMemoryJoinHash.java プロジェクト: jzmq/presto
  public InMemoryJoinHash(
      LongArrayList addresses,
      PagesHashStrategy pagesHashStrategy,
      OperatorContext operatorContext) {
    this.addresses = checkNotNull(addresses, "addresses is null");
    this.pagesHashStrategy = checkNotNull(pagesHashStrategy, "pagesHashStrategy is null");
    this.channelCount = pagesHashStrategy.getChannelCount();

    checkNotNull(operatorContext, "operatorContext is null");

    // reserve memory for the arrays
    int hashSize = HashCommon.arraySize(addresses.size(), 0.75f);
    operatorContext.reserveMemory(sizeOfIntArray(hashSize) + sizeOfIntArray(addresses.size()));

    mask = hashSize - 1;
    key = new int[hashSize];
    Arrays.fill(key, -1);

    this.positionLinks = new int[addresses.size()];
    Arrays.fill(positionLinks, -1);

    // index pages
    for (int position = 0; position < addresses.size(); position++) {
      int pos = ((int) Murmur3.hash64(hashPosition(position))) & mask;

      // look for an empty slot or a slot containing this key
      while (key[pos] != -1) {
        int currentKey = key[pos];
        if (positionEqualsPosition(currentKey, position)) {
          // found a slot for this key
          // link the new key position to the current key position
          positionLinks[position] = currentKey;

          // key[pos] updated outside of this loop
          break;
        }
        // increment position and mask to handler wrap around
        pos = (pos + 1) & mask;
      }

      key[pos] = position;
    }
  }
コード例 #6
0
 /**
  * Check that we score items but do not provide scores for items the user has previously rated.
  * User 5 has rated only item 8 previously.
  */
 @Test
 public void testItemScorerNoRating() {
   long[] items = {7, 8};
   ItemItemScorer scorer = session.get(ItemItemScorer.class);
   assertThat(scorer, notNullValue());
   SparseVector scores = scorer.score(5, LongArrayList.wrap(items));
   assertThat(scores, notNullValue());
   assertThat(scores.size(), equalTo(1));
   assertThat(scores.get(7), not(notANumber()));
   assertThat(scores.containsKey(8), equalTo(false));
 }
コード例 #7
0
  /**
   * Check that we score items but do not provide scores for items the user has previously rated.
   * User 5 has rated only item 8 previously.
   */
  @Test
  public void testItemScorerChannels() {
    long[] items = {7, 8};
    ItemItemScorer scorer = session.get(ItemItemScorer.class);
    assertThat(scorer, notNullValue());
    SparseVector scores = scorer.score(5, LongArrayList.wrap(items));
    assertThat(scores, notNullValue());
    assertThat(scores.size(), equalTo(1));
    assertThat(scores.get(7), not(notANumber()));
    assertThat(
        scores.getChannelVector(ItemItemScorer.NEIGHBORHOOD_SIZE_SYMBOL).get(7),
        closeTo(1.0, 1.0e-5));
    assertThat(scores.containsKey(8), equalTo(false));

    long[] items2 = {7, 8, 9};
    scorer = session.get(ItemItemScorer.class);
    assertThat(scorer, notNullValue());
    scores = scorer.score(2, LongArrayList.wrap(items2));
    assertThat(
        scores.getChannelVector(ItemItemScorer.NEIGHBORHOOD_SIZE_SYMBOL).get(9),
        closeTo(3.0, 1.0e-5)); // 1, 7, 8
  }
コード例 #8
0
  /**
   * Get the keys of this vector sorted by the value of the items stored for each key.
   *
   * @param decreasing If {@code true}, sort in decreasing order.
   * @return The sorted list of keys of this vector.
   */
  public LongArrayList keysByValue(boolean decreasing) {
    long[] skeys = keySet().toLongArray();

    LongComparator cmp;
    // Set up the comparator. We use the key as a secondary comparison to get
    // a reproducible sort irrespective of sorting algorithm.
    if (decreasing) {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k2), get(k1));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    } else {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k1), get(k2));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    }

    LongArrays.quickSort(skeys, cmp);
    return LongArrayList.wrap(skeys);
  }