Ejemplo n.º 1
0
 public TreeHeader(MultiKeyDictionary2 <K, V> rootNode, IEqualityComparer <K> keyComparer)
 {
     RootNode      = rootNode;
     KeyComparer   = keyComparer;
     ValueMap      = new Dictionary <uint, V>();
     KeyMap        = new Dictionary <uint, IEnumerable <K> >();
     _threadLock   = new object();
     _identitySeed = 0;
 }
Ejemplo n.º 2
0
        public static MultiKeyDictionary2 <K, V> ToMultiKeyDictionary2Ex <T, K, V>(this IEnumerable <T> source, IEnumerable <Func <T, K> > keySelectors, Func <T, V> valueSelector)
        {
            var result         = new MultiKeyDictionary2 <K, V>();
            var keySelectorArr = keySelectors as Func <T, K>[] ?? keySelectors.ToArray();

            foreach (var item in source)
            {
                var key = keySelectorArr.Select(keySelector => keySelector(item));
                result.Add(key, valueSelector(item));
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void SetInternal(IEnumerable <K> keys, V val, Queue <K> traversalList = null)
        {
            if (!keys.Any())
            {
                throw new ArgumentException("Keys was empty", "keys");
            }

            if (traversalList == null)
            {
                traversalList = new Queue <K>();
            }

            var head = keys.Take(1).Single();

            if (typeof(K) == typeof(object))
            {
                head = (K)Tools.Object.SanitizeObject(head);
            }
            var tail = keys.Skip(1);

            MultiKeyDictionary2 <K, V> childNode;

            if (_childNodes.ContainsKey(head))
            {
                childNode = _childNodes[head];
            }
            else
            {
                childNode = new MultiKeyDictionary2 <K, V>(this);
                _childNodes.Add(head, childNode);
            }
            traversalList.Enqueue(head);
            if (tail.Any())
            {
                childNode.SetInternal(tail, val, traversalList);
            }
            else
            {
                childNode._hasValue = true;
                _tree.ValueMap[childNode._surrogateKey] = val;
                _tree.KeyMap[childNode._surrogateKey]   = (from x in traversalList select x).ToArray();
            }
            traversalList.Dequeue();
        }
Ejemplo n.º 4
0
 private MultiKeyDictionary2(MultiKeyDictionary2 <K, V> parent)
 {
     _tree = parent._tree;
     Initialize();
 }
Ejemplo n.º 5
0
 internal MultiKeyLookup(IEqualityComparer <K> comparer)
 {
     InternalLookup = new MultiKeyDictionary2 <K, List <V> >(comparer);
 }