docs: public int addElementAtPosition(int prevNode, int nextNode, int element,
  			boolean bUnique, boolean bCallCompare, int treap) {
  		int treap_ = treap;
  		if (treap_ == -1) {
  			if (m_defaultTreap == nullNode())
  				m_defaultTreap = createTreap(-1);
  			treap_ = m_defaultTreap;
  		}
  
  		// dbg_check_(m_root);
  		if (getRoot_(treap_) == nullNode()) {
  			assert (nextNode == nullNode() && prevNode == nullNode());
  			int root = newNode_(element);
  			setRoot_(root, treap_);
  			addToList_(-1, root, treap_);
  			return root;
  		}
  
  		int cmpNext;
  		int cmpPrev;
  		if (bCallCompare) {
  			cmpNext = nextNode != nullNode() ? m_comparator.compare(this,
  					element, nextNode) : -1;
  			assert (cmpNext <= 0);
  			cmpPrev = prevNode != nullNode() ? m_comparator.compare(this,
  					element, prevNode) : 1;
  			// cmpPrev can be negative in plane sweep when intersection is
  			// detected.
  		} else {
  			cmpNext = -1;
  			cmpPrev = 1;
  		}
  
  		if (bUnique && (cmpNext == 0 || cmpPrev == 0)) {
  			m_comparator.onAddUniqueElementFailedImpl_(element);
  			int cur = cmpNext == 0 ? nextNode : prevNode;
  			setDuplicateElement_(cur, treap_);
  			return -1;// return negative value.
  		}
  
  		int cur;
  		int cmp;
  		boolean bNext;
  		if (nextNode != nullNode() && prevNode != nullNode()) {
  			// randomize the the cost to insert a node.
  			bNext = m_random > NumberUtils.nextRand(m_random) >> 1;
  		} else
  			bNext = nextNode != nullNode();
  
  		if (bNext) {
  			cmp = cmpNext;
  			cur = nextNode;
  		} else {
  			cmp = cmpPrev;
  			cur = prevNode;
  		}
  
  		int newNode = -1;
  		int before = -1;
  		boolean b_first = true;
  		for (;;) {
  			if (cmp < 0) {
  				int left = getLeft(cur);
  				if (left != nullNode())
  					cur = left;
  				else {
  					before = cur;
  					newNode = newNode_(element);
  					setLeft_(cur, newNode);
  					setParent_(newNode, cur);
  					break;
  				}
  			} else {
  				int right = getRight(cur);
  				if (right != nullNode())
  					cur = right;
  				else {
  					before = getNext(cur);
  					newNode = newNode_(element);
  					setRight_(cur, newNode);
  					setParent_(newNode, cur);
  					break;
  				}
  			}
  
  			if (b_first) {
  				cmp *= -1;
  				b_first = false;
  			}
  		}
  
  		bubbleUp_(newNode);
  		if (getParent(newNode) == nullNode())
  			setRoot_(newNode, treap_);
  
  		addToList_(before, newNode, treap_);
  		// dbg_check_(m_root);
  		return newNode;
  	}