Exemplo n.º 1
0
        public bool FindFirst(TKey keyVal, out TValue val)
        {
            bool ret = false;

            val = default(TValue);

            if (null != keyDict)
            {
                InvertedSearcher <TKey, TValue> dictionaryVal = null;
                if (keyDict.TryGetValue(keyVal, out dictionaryVal))
                {
                    val = dictionaryVal.valueItem;
                    ret = true;
                }
                else
                {
                    foreach (KeyValuePair <TKey, InvertedSearcher <TKey, TValue> > item in keyDict)
                    {
                        ret = item.Value.FindFirst(keyVal, out val);
                        if (ret)
                        {
                            break;
                        }
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
        public bool Get(IList <TKey> key, out TValue val, out Dictionary <TKey, InvertedSearcher <TKey, TValue> > dictionaryPaths)
        {
            bool ret = false;

            val             = default(TValue);
            dictionaryPaths = null;

            if (level == (key.Count))
            {
                val             = valueItem;
                dictionaryPaths = keyDict;
                ret             = true;
            }
            else
            {
                TKey keyVal = key[level];

                if (null != keyDict)
                {
                    InvertedSearcher <TKey, TValue> dictionaryVal = null;
                    if (keyDict.TryGetValue(keyVal, out dictionaryVal))
                    {
                        ret = dictionaryVal.Get(key, out val, out dictionaryPaths);
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Инициализатор полей класса
 /// </summary>
 private void Init(int level, InvertedSearcher <TKey, TValue> par)
 {
     this.level = level;
     keyDict    = null;
     valueItem  = default(TValue);
     Parent     = par;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Поместить элемент в дерево
        /// </summary>
        /// <param name="key">ключ - должен обеспечивать получение элементов по индексу</param>
        /// <param name="val">значение</param>
        public bool Set(IList <TKey> key, TValue val)
        {
            bool ret = false;

            if (level == (key.Count))
            {
                if (null == valueItem)
                {
                    valueItem = val;
                    ret       = true;
                }
            }
            else
            {
                TKey keyVal = key[level];

                if (null == keyDict)
                {
                    keyDict = new Dictionary <TKey, InvertedSearcher <TKey, TValue> >();
                }

                InvertedSearcher <TKey, TValue> dictionaryVal = null;
                if (!keyDict.TryGetValue(keyVal, out dictionaryVal))
                {
                    dictionaryVal = new InvertedSearcher <TKey, TValue>(level + 1, this);
                    keyDict.Add(keyVal, dictionaryVal);
                }

                ret = dictionaryVal.Set(key, val);
            }

            return(ret);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Закрытый конструктор класса - для внутренней рекурсии
 /// </summary>
 /// <param name="level">уровень вложенности элемента в дереве поиска</param>
 /// <param name="par">ссылка на родительский элемент</param>
 private InvertedSearcher(int level, InvertedSearcher <TKey, TValue> par)
 {
     Init(level, par);
 }