Ejemplo n.º 1
0
  /** {@inheritDoc} */
  public int binarySearch(float value, int fromIndex, int toIndex) {
    if (fromIndex < 0) {
      throw new IndexOutOfBoundsException("begin index can not be < 0");
    }

    if (toIndex > size) {
      throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size);
    }

    if (toIndex < fromIndex) {
      return -(fromIndex + 1);
    }

    TFloatLink middle;
    int mid;
    int from = fromIndex;
    TFloatLink fromLink = getLinkAt(fromIndex);
    int to = toIndex;

    while (from < to) {
      mid = (from + to) >>> 1;
      middle = getLink(fromLink, from, mid);
      if (middle.getValue() == value) return mid;

      if (middle.getValue() < value) {
        from = mid + 1;
        fromLink = middle.next;
      } else {
        to = mid - 1;
      }
    }

    return -(from + 1);
  }
Ejemplo n.º 2
0
 /** {@inheritDoc} */
 public TFloatList inverseGrep(TFloatProcedure condition) {
   TFloatList ret = new TFloatLinkedList();
   for (TFloatLink l = head; got(l); l = l.getNext()) {
     if (!condition.execute(l.getValue())) ret.add(l.getValue());
   }
   return ret;
 }
Ejemplo n.º 3
0
  /** {@inheritDoc} */
  public float min() {
    float ret = Float.POSITIVE_INFINITY;

    if (isEmpty()) throw new IllegalStateException();

    for (TFloatLink l = head; got(l); l = l.getNext()) {
      if (ret > l.getValue()) ret = l.getValue();
    }

    return ret;
  }
Ejemplo n.º 4
0
  /** {@inheritDoc} */
  public int indexOf(int offset, float value) {
    int count = offset;

    TFloatLink l;
    for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) {
      if (l.getValue() == value) return count;

      count++;
    }

    if (l != null && l.getValue() == value) return count;

    return -1;
  }
Ejemplo n.º 5
0
 /** {@inheritDoc} */
 public void shuffle(Random rand) {
   for (int i = 0; i < size; i++) {
     TFloatLink l = getLinkAt(rand.nextInt(size()));
     removeLink(l);
     add(l.getValue());
   }
 }
Ejemplo n.º 6
0
  /** {@inheritDoc} */
  public boolean contains(float value) {
    if (isEmpty()) return false;

    for (TFloatLink l = head; got(l); l = l.getNext()) {
      if (l.getValue() == value) return true;
    }
    return false;
  }
Ejemplo n.º 7
0
 /** {@inheritDoc} */
 public void transformValues(TFloatFunction function) {
   for (TFloatLink l = head; got(l); ) {
     //
     l.setValue(function.execute(l.getValue()));
     //
     l = l.getNext();
   }
 }
Ejemplo n.º 8
0
  /** {@inheritDoc} */
  public float removeAt(int offset) {
    TFloatLink l = getLinkAt(offset);
    if (no(l)) throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset);

    float prev = l.getValue();
    removeLink(l);
    return prev;
  }
Ejemplo n.º 9
0
  /** {@inheritDoc} */
  public float sum() {
    float sum = 0;

    for (TFloatLink l = head; got(l); l = l.getNext()) {
      sum += l.getValue();
    }

    return sum;
  }
Ejemplo n.º 10
0
  /** {@inheritDoc} */
  public float get(int offset) {
    if (offset > size)
      throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size);

    TFloatLink l = getLinkAt(offset);
    //
    if (no(l)) return no_entry_value;

    return l.getValue();
  }
Ejemplo n.º 11
0
  /** {@inheritDoc} */
  public float set(int offset, float val) {
    if (offset > size)
      throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size);

    TFloatLink l = getLinkAt(offset);
    //
    if (no(l)) throw new IndexOutOfBoundsException("at offset " + offset);

    float prev = l.getValue();
    l.setValue(val);
    return prev;
  }
Ejemplo n.º 12
0
  /** {@inheritDoc} */
  public boolean remove(float value) {
    boolean changed = false;
    for (TFloatLink l = head; got(l); l = l.getNext()) {
      //
      if (l.getValue() == value) {
        changed = true;
        //
        removeLink(l);
      }
    }

    return changed;
  }
Ejemplo n.º 13
0
  /** {@inheritDoc} */
  public int lastIndexOf(int offset, float value) {
    if (isEmpty()) return -1;

    int last = -1;
    int count = offset;
    for (TFloatLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) {
      if (l.getValue() == value) last = count;

      count++;
    }

    return last;
  }
Ejemplo n.º 14
0
  /** {@inheritDoc} */
  public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) {
    if (len == 0) {
      return dest; // nothing to copy
    }
    if (source_pos < 0 || source_pos >= size()) {
      throw new ArrayIndexOutOfBoundsException(source_pos);
    }

    TFloatLink tmp = getLinkAt(source_pos);
    for (int i = 0; i < len; i++) {
      dest[dest_pos + i] = tmp.getValue(); // copy
      tmp = tmp.getNext();
    }

    return dest;
  }
Ejemplo n.º 15
0
  /** {@inheritDoc} */
  public TFloatList subList(int begin, int end) {
    if (end < begin) {
      throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end);
    }
    if (size < begin) {
      throw new IllegalArgumentException(
          "begin index " + begin + " greater than last index " + size);
    }
    if (begin < 0) {
      throw new IndexOutOfBoundsException("begin index can not be < 0");
    }
    if (end > size) {
      throw new IndexOutOfBoundsException("end index < " + size);
    }

    TFloatLinkedList ret = new TFloatLinkedList();
    TFloatLink tmp = getLinkAt(begin);
    for (int i = begin; i < end; i++) {
      ret.add(tmp.getValue()); // copy
      tmp = tmp.getNext();
    }

    return ret;
  }
Ejemplo n.º 16
0
 /** {@inheritDoc} */
 public boolean forEach(TFloatProcedure procedure) {
   for (TFloatLink l = head; got(l); l = l.getNext()) {
     if (!procedure.execute(l.getValue())) return false;
   }
   return true;
 }
Ejemplo n.º 17
0
 /** {@inheritDoc} */
 public boolean forEachDescending(TFloatProcedure procedure) {
   for (TFloatLink l = tail; got(l); l = l.getPrevious()) {
     if (!procedure.execute(l.getValue())) return false;
   }
   return true;
 }