// (c) 2000 Benjamin Fry, MIT Media Laboratory, fry@media.mit.edu
// Aesthetics + Computation Group, Massachussetts Institute of Technology


// what's your vector, victor?
// vector-like object to be used to keep track of clusters in cast

public class Victor {
  int length;
  int item[];
  float affinity[];


  public Victor() {
    item = new int[10];
    affinity = new float[10];
  }


  public void add(int what) {
    add(what, 0);
  }

  public void add(int what, float whata) {
    if (length == item.length) {
      int temp[] = new int[length*2];
      System.arraycopy(item, 0, temp, 0, length);
      item = temp;

      float atemp[] = new float[length*2];
      System.arraycopy(affinity, 0, atemp, 0, length);
      affinity = atemp;
    }
    item[length] = what;
    affinity[length] = whata;
    length++;
  }


  public void remove(int what) {
    int found = -1;
    for (int i = 0; i < length; i++) {
      if (item[i] == what) {
	found = i;
	break;
      }
    }
    if (found == -1) {
      System.err.println("vector doesn't contain " + what);
      System.exit(1);
    }
    removeIndex(found);
  }


  public void removeIndex(int index) {
    for (int i = index; i < length-1; i++) {
      item[i] = item[i+1];
      affinity[i] = affinity[i+1];
    }
    length--;
  }


  public void move(int index, Victor c) {
    c.add(item[index], affinity[index]);
    removeIndex(index);
  }
}

