protected virtual void OnLowChild(TstDictionaryEntry p)
 {
     if (this.LowChild != null)
     {
         this.LowChild(this, new TstDictionaryEntryEventArgs(p));
     }
 }
 protected virtual void OnTreeEntry(TstDictionaryEntry p)
 {
     if (this.TreeEntry != null)
     {
         this.TreeEntry(this, new TstDictionaryEntryEventArgs(p));
     }
 }
 internal void PartialMatchSearch(TstDictionaryEntry p, string key, int index, char wildChar, IList matches)
 {
     if (p != null)
     {
         char ch1 = key[index];
         if ((ch1 == wildChar) || (ch1 < p.SplitChar))
         {
             this.PartialMatchSearch(p.LowChild, key, index, wildChar, matches);
         }
         if ((ch1 == wildChar) || (ch1 == p.SplitChar))
         {
             if (index < (key.Length - 1))
             {
                 this.PartialMatchSearch(p.EqChild, key, index + 1, wildChar, matches);
             }
             else if (p.IsKey)
             {
                 matches.Add(new DictionaryEntry(p.Key, p.Value));
             }
         }
         if ((ch1 == wildChar) || (ch1 > p.SplitChar))
         {
             this.PartialMatchSearch(p.HighChild, key, index, wildChar, matches);
         }
     }
 }
 protected TstDictionary(TstDictionaryEntry root)
 {
     if (root == null)
     {
         throw new ArgumentNullException("root is null");
     }
     this.root    = root;
     this.version = 0;
 }
        public virtual bool ContainsKey(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            TstDictionaryEntry entry1 = this.Find(key);

            return((entry1 != null) && entry1.IsKey);
        }
 public TstDictionaryEntry(TstDictionaryEntry parent, char splitChar)
 {
     this.isKey     = false;
     this.key       = null;
     this.value     = null;
     this.parent    = parent;
     this.splitChar = splitChar;
     this.lowChild  = null;
     this.eqChild   = null;
     this.highChild = null;
 }
 protected void Traverse(TstDictionaryEntry p)
 {
     if (p != null)
     {
         this.OnTreeEntry(p);
         this.OnLowChild(p.LowChild);
         this.Traverse(p.LowChild);
         this.OnEqChild(p.EqChild);
         this.Traverse(p.EqChild);
         this.OnHighChild(p.HighChild);
         this.Traverse(p.HighChild);
     }
 }
        public virtual void Remove(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key is null");
            }
            if (key.Length == 0)
            {
                throw new ArgumentException("key length cannot be 0");
            }
            if (this.IsReadOnly)
            {
                throw new NotSupportedException("dictionary is read-only");
            }
            if (this.IsFixedSize)
            {
                throw new NotSupportedException("dictionary has fixed size");
            }
            this.version++;
            TstDictionaryEntry entry1 = this.Find(key);

            if (entry1 != null)
            {
                entry1.IsKey = false;
                entry1.Key   = null;
                while ((!entry1.IsKey && !entry1.HasChildren) && (entry1.Parent != null))
                {
                    if (entry1.IsLowChild)
                    {
                        entry1.Parent.LowChild = null;
                    }
                    else if (entry1.IsHighChild)
                    {
                        entry1.Parent.HighChild = null;
                    }
                    else
                    {
                        entry1.Parent.EqChild = null;
                    }
                    entry1 = entry1.Parent;
                }
                if ((!entry1.IsKey && !entry1.HasChildren) && (entry1 == this.root))
                {
                    this.root = null;
                }
            }
        }
 public virtual object this[string key]
 {
     get
     {
         if (key == null)
         {
             throw new ArgumentNullException("key");
         }
         TstDictionaryEntry entry1 = this.Find(key);
         if (entry1 == null)
         {
             return(null);
         }
         return(entry1.Value);
     }
     set
     {
         if (key == null)
         {
             throw new ArgumentNullException("key");
         }
         if (key.Length == 0)
         {
             throw new ArgumentException("key is an empty string");
         }
         if (this.IsReadOnly)
         {
             throw new NotSupportedException("read-only dictionary");
         }
         this.version++;
         TstDictionaryEntry entry1 = this.Find(key);
         if (entry1 == null)
         {
             this.Add(key, value);
         }
         else
         {
             if (this.IsFixedSize)
             {
                 throw new NotSupportedException("fixed-size dictionary");
             }
             entry1.Value = value;
         }
     }
 }
        public object Clone()
        {
            TstDictionaryEntry entry1 = new TstDictionaryEntry(this.Parent, this.SplitChar);

            if (this.LowChild != null)
            {
                entry1.LowChild = this.LowChild.Clone() as TstDictionaryEntry;
            }
            if (this.EqChild != null)
            {
                entry1.EqChild = this.EqChild.Clone() as TstDictionaryEntry;
            }
            if (this.HighChild != null)
            {
                entry1.HighChild = this.HighChild.Clone() as TstDictionaryEntry;
            }
            return(entry1);
        }
        public virtual TstDictionaryEntry Find(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            int num1 = key.Length;

            if (num1 == 0)
            {
                return(null);
            }
            TstDictionaryEntry entry1 = this.Root;
            int num2 = 0;

            while ((num2 < num1) && (entry1 != null))
            {
                char ch1 = key[num2];
                if (ch1 < entry1.SplitChar)
                {
                    entry1 = entry1.LowChild;
                    continue;
                }
                if (ch1 > entry1.SplitChar)
                {
                    entry1 = entry1.HighChild;
                    continue;
                }
                if (num2 == (num1 - 1))
                {
                    return(entry1);
                }
                num2++;
                entry1 = entry1.EqChild;
            }
            return(entry1);
        }
 internal void NearNeighborsSearch(TstDictionaryEntry p, string key, int index, int dist, IList matches)
 {
     if ((p != null) && (dist >= 0))
     {
         char ch1 = key[index];
         if ((dist > 0) || (ch1 < p.SplitChar))
         {
             this.NearNeighborsSearch(p.LowChild, key, index, dist, matches);
         }
         if (p.IsKey)
         {
             if ((key.Length - index) <= dist)
             {
                 matches.Add(new DictionaryEntry(p.Key, p.Value));
             }
         }
         else
         {
             int num1 = index;
             if (num1 != (key.Length - 1))
             {
                 num1++;
             }
             int num2 = dist;
             if (ch1 != p.SplitChar)
             {
                 num2--;
             }
             this.NearNeighborsSearch(p.EqChild, key, num1, num2, matches);
         }
         if ((dist > 0) || (ch1 > p.SplitChar))
         {
             this.NearNeighborsSearch(p.HighChild, key, index, dist, matches);
         }
     }
 }
 public TstDictionaryEntryEventArgs(TstDictionaryEntry entry)
 {
     this.entry = entry;
 }
        public virtual void Add(string key, object value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key is null");
            }
            if (key.Length == 0)
            {
                throw new ArgumentException("trying to add empty key");
            }
            if (this.IsReadOnly)
            {
                throw new NotSupportedException("dictionary is read-only");
            }
            if (this.IsFixedSize)
            {
                throw new NotSupportedException("dictionary has fixed size");
            }
            this.version++;
            if (this.Root == null)
            {
                this.root = new TstDictionaryEntry(null, key[0]);
            }
            TstDictionaryEntry entry1 = this.Root;
            int num1 = 0;

            while (num1 < key.Length)
            {
                char ch1 = key[num1];
                if (ch1 < entry1.SplitChar)
                {
                    if (entry1.LowChild == null)
                    {
                        entry1.LowChild = new TstDictionaryEntry(entry1, ch1);
                    }
                    entry1 = entry1.LowChild;
                    continue;
                }
                if (ch1 > entry1.SplitChar)
                {
                    if (entry1.HighChild == null)
                    {
                        entry1.HighChild = new TstDictionaryEntry(entry1, ch1);
                    }
                    entry1 = entry1.HighChild;
                    continue;
                }
                num1++;
                if (num1 == key.Length)
                {
                    if (entry1.IsKey)
                    {
                        throw new ArgumentException("key already in dictionary");
                    }
                    break;
                }
                if (entry1.EqChild == null)
                {
                    entry1.EqChild = new TstDictionaryEntry(entry1, key[num1]);
                }
                entry1 = entry1.EqChild;
            }
            entry1.IsKey = true;
            entry1.Key   = key;
            entry1.Value = value;
        }