/**
   * Increments the value at the given index by the given value.
   *
   * @param index the index of the value to alter
   * @param val the value to be added to the index
   */
  @Override
  public void increment(int index, double val) {
    if (index > length - 1 || index < 0)
      throw new IndexOutOfBoundsException(
          "Can not access an index larger then the vector or a negative index");

    int location = Arrays.binarySearch(indexes, 0, used, index);
    if (location < 0 && val != 0) // dont insert zeros!
    insertValue(location, index, val);
    else {
      values[location] += val;
      if (values[location] == 0.0) removeNonZero(location);
    }
  }
  @Override
  public void set(int index, double val) {
    if (index > length() - 1 || index < 0)
      throw new IndexOutOfBoundsException(index + " does not fit in [0," + length + ")");

    clearCaches();
    int insertLocation = Arrays.binarySearch(indexes, 0, used, index);
    if (insertLocation >= 0) {
      if (val != 0) // set it
      values[insertLocation] = val;
      else // shift used count and everyone over
      {
        removeNonZero(insertLocation);
      }
    } else if (val != 0) // dont insert 0s, that is stupid
    insertValue(insertLocation, index, val);
  }