/** * Adds the given element to this tree, if it's not already present. * * @param element element */ public void Add(TKey key, TValue value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (Root == null) { Root = new MutableBkTreeNode <TKey, TValue>(key, value); } else { var node = Root; while (!node.Key.Equals(key)) { var distance = Distance(node.Key, key); var parent = node; if (!parent.ChildrenByDistance.ContainsKey(distance)) { node = new MutableBkTreeNode <TKey, TValue>(key, value); parent.ChildrenByDistance.Add(distance, node); break; } node = parent.ChildrenByDistance[distance]; } } }
private Boolean Equals(MutableBkTreeNode <TKey, TValue> other) => Equals(Key, other.Key) && Equals(ChildrenByDistance, other.ChildrenByDistance);