public void ChangeHeight(TreapNode o, double difference) { lock (root) { TreapNode.Split(root, out TreapNode a, out TreapNode b, o.GetPosition() + 1); if (b != null) { b.AppendAnimation(DateTime.Now, difference); } root = TreapNode.Merge(a, b); } }
private double QueryFinal(int position) { double ans; TreapNode b; lock (root) { TreapNode.Split(root, out b, out TreapNode c, position + 1); TreapNode.Split(b, out TreapNode a, out b, position); ans = b.QueryFinalYOffset(); root = TreapNode.Merge(a, TreapNode.Merge(b, c)); } return(ans); }
public double Query(int position, Action <TreapNode> callBack = null) { double ans; TreapNode b; lock (root) { TreapNode.Split(root, out b, out TreapNode c, position + 1); TreapNode.Split(b, out TreapNode a, out b, position); ans = b.QueryYOffset(); root = TreapNode.Merge(a, TreapNode.Merge(b, c)); } callBack?.Invoke(b); return(ans); }
public TreapNode Delete(int position) { lock (root) { TreapNode.Split(root, out TreapNode b, out TreapNode c, position + 1); TreapNode.Split(b, out TreapNode a, out b, position); if (c != null) { c.AppendAnimation(DateTime.Now, -itemHeight); } root = TreapNode.Merge(a, c); OnDataRemoved(b.data); return(b); } }
public TreapNode Insert(DataType data, int position) { var height = QueryFinal(position);// (position <= Count ? : position * itemHeight); try { lock (root) { TreapNode.Split(root, out TreapNode a, out TreapNode b, position); if (b != null) { b.AppendAnimation(DateTime.Now, itemHeight); } var o = new TreapNode(data, height); root = TreapNode.Merge(a, TreapNode.Merge(o, b)); return(o); } } finally { OnDataInserted(data); } }