예제 #1
0
  @Test
  public void testPairsMatching() {
    IntArrayList keyList = new IntArrayList();
    ByteArrayList valueList = new ByteArrayList();
    OpenIntByteHashMap map = new OpenIntByteHashMap();
    map.put((int) 11, (byte) 22);
    map.put((int) 12, (byte) 23);
    map.put((int) 13, (byte) 24);
    map.put((int) 14, (byte) 25);
    map.removeKey((int) 13);
    map.pairsMatching(
        new IntByteProcedure() {

          @Override
          public boolean apply(int first, byte second) {
            return (first % 2) == 0;
          }
        },
        keyList,
        valueList);
    keyList.sort();
    valueList.sort();
    assertEquals(2, keyList.size());
    assertEquals(2, valueList.size());
    assertEquals(12, keyList.get(0));
    assertEquals(14, keyList.get(1));
    assertEquals(23, valueList.get(0));
    assertEquals(25, valueList.get(1));
  }
예제 #2
0
  /**
   * Fills all values contained in the receiver into the specified list. Fills the list, starting at
   * index 0. After this call returns the specified list has a new size that equals
   * <tt>this.size()</tt>. Iteration order is guaranteed to be <i>identical</i> to the order used by
   * method {@link #forEachKey(DoubleProcedure)}.
   *
   * <p>This method can be used to iterate over the values of the receiver.
   *
   * @param list the list to be filled, can have any size.
   */
  @Override
  public void values(ByteArrayList list) {
    list.setSize(distinct);
    byte[] elements = list.elements();

    int j = 0;
    for (int i = state.length; i-- > 0; ) {
      if (state[i] == FULL) {
        elements[j++] = values[i];
      }
    }
  }
예제 #3
0
  /**
   * Fills all pairs satisfying a given condition into the specified lists. Fills into the lists,
   * starting at index 0. After this call returns the specified lists both have a new size, the
   * number of pairs satisfying the condition. Iteration order is guaranteed to be <i>identical</i>
   * to the order used by method {@link #forEachKey(DoubleProcedure)}.
   *
   * <p><b>Example:</b> <br>
   *
   * <pre>
   * DoubleByteProcedure condition = new DoubleByteProcedure() { // match even values only
   * public boolean apply(double key, byte value) { return value%2==0; }
   * }
   * keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
   * </pre>
   *
   * @param condition the condition to be matched. Takes the current key as first and the current
   *     value as second argument.
   * @param keyList the list to be filled with keys, can have any size.
   * @param valueList the list to be filled with values, can have any size.
   */
  @Override
  public void pairsMatching(
      DoubleByteProcedure condition, DoubleArrayList keyList, ByteArrayList valueList) {
    keyList.clear();
    valueList.clear();

    for (int i = table.length; i-- > 0; ) {
      if (state[i] == FULL && condition.apply(table[i], values[i])) {
        keyList.add(table[i]);
        valueList.add(values[i]);
      }
    }
  }
예제 #4
0
 @Test
 public void testValues() {
   OpenIntByteHashMap map = new OpenIntByteHashMap();
   map.put((int) 11, (byte) 22);
   map.put((int) 12, (byte) 23);
   map.put((int) 13, (byte) 24);
   map.put((int) 14, (byte) 25);
   map.removeKey((int) 13);
   ByteArrayList values = new ByteArrayList(100);
   map.values(values);
   assertEquals(3, values.size());
   values.sort();
   assertEquals(22, values.get(0));
   assertEquals(23, values.get(1));
   assertEquals(25, values.get(2));
 }
예제 #5
0
  @Test
  public void testPairsSortedByKey() {
    OpenIntByteHashMap map = new OpenIntByteHashMap();
    map.put((int) 11, (byte) 100);
    map.put((int) 12, (byte) 70);
    map.put((int) 13, (byte) 30);
    map.put((int) 14, (byte) 3);

    IntArrayList keys = new IntArrayList();
    ByteArrayList values = new ByteArrayList();
    map.pairsSortedByKey(keys, values);

    assertEquals(4, keys.size());
    assertEquals(4, values.size());
    assertEquals((int) 11, keys.get(0));
    assertEquals((byte) 100, values.get(0));
    assertEquals((int) 12, keys.get(1));
    assertEquals((byte) 70, values.get(1));
    assertEquals((int) 13, keys.get(2));
    assertEquals((byte) 30, values.get(2));
    assertEquals((int) 14, keys.get(3));
    assertEquals((byte) 3, values.get(3));
    keys.clear();
    values.clear();
    map.pairsSortedByValue(keys, values);
    assertEquals((int) 11, keys.get(3));
    assertEquals((byte) 100, values.get(3));
    assertEquals((int) 12, keys.get(2));
    assertEquals((byte) 70, values.get(2));
    assertEquals((int) 13, keys.get(1));
    assertEquals((byte) 30, values.get(1));
    assertEquals((int) 14, keys.get(0));
    assertEquals((byte) 3, values.get(0));
  }