コード例 #1
0
        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);
                }
コード例 #2
0
        public void Add([NotNull] TKey key, IDictionaryTreeNode <TKey, TValue> value)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            Tree.Add(key, value);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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;
            }
        }
コード例 #10
0
 public Boolean Remove(TKey key, out IDictionaryTreeNode <TKey, TValue> value, params TKey[] sections)
 {
     return(Remove(key, sections, out value));
 }