public PersistentMap <K, T> Assign(K key, T value) { if (root == null) { return(new PersistentTreapMap <K, T>(new TreapNode(key, value))); } TreapNode y = root.Find(key); if (y == null) { return(new PersistentTreapMap <K, T>(root.Insert(new TreapNode(key, value)))); } return(new PersistentTreapMap <K, T>(root.Change(key, value))); }
public TreapNode Find(K k) { int b = k.CompareTo(key); if (b == 0) { return(this); } if (b < 0) { return(left != null?left.Find(k) : null); } else { return(right != null?right.Find(k) : null); } }
public TreapNode <T> Find(T query) { if (val.Equals(query)) { return(this); } if (left != null) { var res = left.Find(query); if (res != null) { return(res); } } if (right != null) { var res = right.Find(query); if (res != null) { return(res); } } return(null); }