Exemplo n.º 1
0
  /**
   * Fills all keys 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 keys of the receiver.
   *
   * @param list the list to be filled, can have any size.
   */
  public void keys(DoubleArrayList list) {
    list.setSize(distinct);
    double[] elements = list.elements();

    double[] tab = table;
    byte[] stat = state;

    int j = 0;
    for (int i = tab.length; i-- > 0; ) {
      if (stat[i] == FULL) elements[j++] = tab[i];
    }
  }
Exemplo n.º 2
0
  /**
   * Adds the part of the specified list between indexes <tt>from</tt> (inclusive) and <tt>to</tt>
   * (inclusive) to the receiver.
   *
   * @param values the list of which elements shall be added.
   * @param from the index of the first element to be added (inclusive).
   * @param to the index of the last element to be added (inclusive).
   */
  public void addAllOfFromTo(DoubleArrayList values, int from, int to) {
    /*
    // the obvious version, but we can do quicker...
    double[] theValues = values.elements();
    int theSize=values.size();
    for (int i=0; i<theSize; ) add(theValues[i++]);
    */

    double[] valuesToAdd = values.elements();
    int k = this.bufferSet.k();
    int bufferSize = k;
    double[] bufferValues = null;
    if (currentBufferToFill != null) {
      bufferValues = currentBufferToFill.values.elements();
      bufferSize = currentBufferToFill.size();
    }

    for (int i = from - 1; ++i <= to; ) {
      if (sampleNextElement()) {
        if (bufferSize == k) { // full
          if (bufferSet._getFirstEmptyBuffer() == null) collapse();
          newBuffer();
          if (!currentBufferToFill.isAllocated) currentBufferToFill.allocate();
          currentBufferToFill.isSorted = false;
          bufferValues = currentBufferToFill.values.elements();
          bufferSize = 0;
        }

        bufferValues[bufferSize++] = valuesToAdd[i];
        if (bufferSize == k) { // full
          currentBufferToFill.values.setSize(bufferSize);
          currentBufferToFill = null;
        }
      }
    }
    if (this.currentBufferToFill != null) {
      this.currentBufferToFill.values.setSize(bufferSize);
    }

    this.totalElementsFilled += to - from + 1;
  }