public void RemoveEmpty([NotNull] TKey key) { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> node = GetChild(key); if (node is null) { return; } if (node.FullCount <= 0 && node.Value.IsDefault()) { Remove(key); return; } if (node.FullCount <= 0) { return; } foreach ((TKey dictkey, IDictionaryTreeNode <TKey, TValue> dict) in node) { if (dict is null || dict.Count <= 0 && dict.Value.IsDefault()) { node.Tree.Remove(dictkey); }
public void Add([NotNull] TKey key, IDictionaryTreeNode <TKey, TValue> value) { if (key is null) { throw new ArgumentNullException(nameof(key)); } Tree.Add(key, value); }
public IDictionaryTreeNode <TKey, TValue> GetChildSection(IEnumerable <TKey> sections) { if (sections is null) { return(null); } IDictionaryTreeNode <TKey, TValue> node = Node; return(sections.WhereNotNull().Any(section => !node.TryGetValue(section, out node)) ? null : node); }
public Boolean TryGetValue([NotNull] TKey key, out IDictionaryTreeNode <TKey, TValue> value) { if (key is null) { throw new ArgumentNullException(nameof(key)); } if (HasTree) { return(Tree.TryGetValue(key, out value)); } value = default; return(false); }
public void RemoveEmpty([NotNull] TKey key, IEnumerable <TKey> sections) { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> node = GetChildSection(sections); if (node is null || node.Count <= 0) { return; } node.RemoveEmpty(key); }
public Boolean Remove([NotNull] TKey key, IEnumerable <TKey> sections, out IDictionaryTreeNode <TKey, TValue> value) { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> child = GetChildSection(sections); if (child is not null) { return(child.Tree.Remove(key, out value)); } value = default; return(false); }
public IDictionaryTreeNode <TKey, TValue> GetChild(TKey key, IEnumerable <TKey> sections) { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> node = GetChildSection(sections); if (node is null) { return(null); } node.TryGetValue(key, out IDictionaryTreeNode <TKey, TValue> value); return(value); }
public Boolean TryAdd(TKey key, TValue value) { if (key is null) { throw new ArgumentNullException(nameof(key)); } if (ContainsKey(key)) { return(false); } IDictionaryTreeNode <TKey, TValue> node = CreateNode(); node.Value = value; Add(key, node); return(true); }
public IDictionaryTreeNode <TKey, TValue> this[[NotNull] TKey key, IEnumerable <TKey> sections] { get { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> node = this; if (sections is null) { return(node[key]); } node = sections.WhereNotNull().Aggregate(node, (current, section) => current[section]); return(node[key]); } set { if (key is null) { throw new ArgumentNullException(nameof(key)); } IDictionaryTreeNode <TKey, TValue> node = this; if (sections is null) { node[key] = value; return; } node = sections.WhereNotNull().Aggregate(node, (current, section) => current[section]); node[key] = value; } }
public Boolean Remove(TKey key, out IDictionaryTreeNode <TKey, TValue> value, params TKey[] sections) { return(Remove(key, sections, out value)); }