Exemple #1
0
  private String nodeString(IntervalNode<Type> node, int level) {
    if (node == null) return "";

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < level; i++) sb.append("\t");
    sb.append(node + "\n");
    sb.append(nodeString(node.getLeft(), level + 1));
    sb.append(nodeString(node.getRight(), level + 1));
    return sb.toString();
  }
Exemple #2
0
 /**
  * Perform an interval query, returning the interval objects Will rebuild the tree if out of sync
  *
  * @param start the start of the interval to check
  * @param end the end of the interval to check
  * @return all intervals that intersect target
  */
 public List<Interval<Type>> getIntervals(long start, long end) {
   build();
   return head.query(new Interval<Type>(start, end, null));
 }
Exemple #3
0
 /**
  * Perform a stabbing query, returning the interval objects Will rebuild the tree if out of sync
  *
  * @param time the time to stab
  * @return all intervals that contain time
  */
 public List<Interval<Type>> getIntervals(long time) {
   build();
   return head.stab(time);
 }
Exemple #4
0
  @Override
  public void runAlgorithm() {
    setHeader("insert", K);
    v = new IntervalNode(T, K, ZDepth.ACTIONNODE);
    v.setInterval(T.numLeafs + 1, T.numLeafs + 1);
    // v.setColor(NodeColor.INSERT);

    T.reposition();

    if (T.root == null) {
      T.root = v;
      v = null;
      if (T.root != null) {
        T.numLeafs++;
        addStep("newroot");
      }
      T.reposition();
      // heap #1 is empty; done;
      return;
    }

    int tmp = T.numLeafs;
    while (tmp % 2 == 0) {
      tmp /= 2;
    }

    if (tmp == 1) {
      T.extend();
      addStep("intervalextend");
      pause();
    }
    T.reposition();
    // pause();

    /*
     * T.root.linkRight(v); T.reposition();
     */
    /*
     * pridaj na T.numLeafs + 1 novy prvok;
     */

    IntervalNode w;
    // T.numLeafs++;
    final int n = T.numLeafs;
    int k = 1 << 10;
    if (n == 0) {
      T.root = w = v;
      v.goToRoot();
      pause();
    } else {
      while ((k & n) == 0) {
        k >>= 1;
      }
      // k >>= 1;
      w = T.root;
      while (k > 1) {
        w = ((n & k) == 0) ? w.getLeft() : w.getRight();
        k >>= 1;
      }
      if ((k & n) == 0) {
        w.linkLeft(v);
      } else {
        w.linkRight(v);
      }
      T.reposition();
    }

    T.numLeafs++;
    addNote("intervalinsert");
    v.mark();
    pause();
    v.unmark();
    /*
     * uprav strom na min/max z intervalu;
     */
    // w = w.getParent();
    // toto prerobit na iba prechod od prave pridaneho vrcholu po koren
    adjustValues(w);
    addNote("done");
  }