public void track(int x) {
    if (root == null) {
      root = new StreamNode(x);
    } else {
      StreamNode runner = root;
      StreamNode parent = root;
      while (runner != null) {
        if (runner.val == x) {
          runner.equalTo++;
          updateTree(runner.right);
          break;
        } else if (runner.val < x) {
          parent = runner;
          runner = runner.right;
        } else {
          parent = runner;
          runner.lessThan++;
          updateTree(runner.right);
          runner = runner.left;
        }
      }
      if (runner == null) {
        StreamNode newNode = new StreamNode(x);
        if (parent.val > x) {
          parent.left = newNode;
          newNode.lessThan = parent.lessThan - 1;
        } else {
          parent.right = newNode;
          newNode.lessThan = 1 + parent.lessThan + parent.equalTo;
        }
      }
    }
  }