Exemplo n.º 1
0
 internal Enumerator(BTClass <TKey, TValue> dictionary, int getEnumeratorRetType)
 {
     this.dictionary           = dictionary;
     this.version              = dictionary.version;
     this.index                = 0;
     this.getEnumeratorRetType = getEnumeratorRetType;
     this.current              = default(KeyValuePair <TKey, TValue>);
 }
Exemplo n.º 2
0
        private static BTClass <TKey, TValue> ReadFromByte(byte[] byteArr)
        {
            MemoryStream    ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();

            ms.Write(byteArr, 0, byteArr.Length);
            ms.Seek(0, SeekOrigin.Begin);
            BTClass <TKey, TValue> res = (BTClass <TKey, TValue>)bf.Deserialize(ms);

            return(res);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Добавить элемент в дерево
        /// </summary>
        /// <param name="key">Ключ для поиска</param>
        /// <param name="val">Значение</param>
        /// <param name="replace">Заменять, если есть такой ключь, иначе Exception</param>
        public virtual void Add(TKey key, TValue val, bool replace = false, BTClass <TKey, TValue> parent = null)
        {
            if (this.entry == null)
            {
                this.entry = new BTClass <TKey, TValue> .Entry();

                this.entry._key   = key;
                this.entry._value = val;
                this._parent      = parent;

                /*if(elements == null)
                 *      elements = new BTClass<TKey, TValue>[1];
                 * if(!Array.Exists(elements,x => (x != null) ? x.compare(this.entry._key) == 0 : false)){
                 *      if(elements[0] != null)
                 *              Array.Resize(ref elements,elements.Length+1);
                 *      elements[elements.Length-1] = this;
                 * }*/
                count++;
                return;
            }
            int result = compare(key);

            if (this._branchs == null)
            {
                this._branchs = new BTClass <TKey, TValue> [2];
            }
            if (result < 0)
            {
                if (this._branchs[0] == null)
                {
                    this._branchs[0] = new BTClass <TKey, TValue>();
                }
                this._branchs[0].Add(key, val, replace, this);
            }
            else if (result > 0)
            {
                if (this._branchs[1] == null)
                {
                    this._branchs[1] = new BTClass <TKey, TValue>();
                }
                this._branchs[1].Add(key, val, replace, this);
            }
            else
            {
                if (replace)
                {
                    this.entry._value = val;
                }
                else
                {
                    throw new Exception("Error key");
                }
            }
        }
Exemplo n.º 4
0
        private static byte[] ToByteArr(BTClass <TKey, TValue> bt)
        {
            if (bt == null)
            {
                return(null);
            }
            BinaryFormatter bf = new BinaryFormatter();

            using (MemoryStream ms = new MemoryStream()){
                bf.Serialize(ms, bt);
                return(ms.ToArray());
            }
        }
Exemplo n.º 5
0
 internal void BranchDown(BTClass <TKey, TValue> bt)        //ERROR
 {
     if (this._branchs != null)
     {
         if (this._branchs[0] == null)
         {
             this._branchs[0]          = new BTClass <TKey, TValue>();
             this._branchs[0]._branchs = bt._branchs;
             this._branchs[0].entry    = bt.entry;
         }
         else
         {
             this._branchs[0].BranchDown(bt);
         }
     }
     else
     {
         this._branchs             = new BTClass <TKey, TValue> [2];
         this._branchs[0]          = new BTClass <TKey, TValue>();
         this._branchs[0]._branchs = bt._branchs;
         this._branchs[0].entry    = bt.entry;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Сохранить данные в файл
 /// </summary>
 /// <param name="PathToFile">Путь к файлу</param>
 /// <param name="bt">Данные</param>
 public static void ToFile(string PathToFile, BTClass <TKey, TValue> bt)
 {
     File.WriteAllBytes(PathToFile, ToByteArr(bt));
 }