public SplayRangeTree(IEnumerable <T> init) : base() { SupportEquatable = false; var p = Root = lnil = new SplayRangeTreeNode <T>(default(T)); // left trailer if (init != null) { foreach (var item in init) { p.RightChild = new SplayRangeTreeNode <T>(item); p = p.RightChild; } } p.RightChild = rnil = new SplayRangeTreeNode <T>(default(T)); // right trailer Splay(p); }
public SplayRangeTreeNode <T> IndexSearch(int index) // index start from 1. { SplayRangeTreeNode <T> p = Root; p.SearchDown(); while (index != p.LeftChild.subcount) { if (index < p.LeftChild.subcount) { p = p.LeftChild; } else { index -= p.LeftChild.subcount + 1; p = p.RightChild; } p.SearchDown(); } return(p); }
protected override void OnSearchDown() { if (Equals(nil)) { return; } if (_rev) { var temp = LeftChild; LeftChild = RightChild; RightChild = temp; LeftChild._rev ^= _rev; RightChild._rev ^= _rev; _rev = false; } if (_operations != null) { LeftChild._operations += _operations; RightChild._operations += _operations; _operations.Invoke(ref _data); _operations = null; } }