示例#1
0
        public T GetVersionContent(Version v)
        {
            ImmutableSortedDictionary <Version, T> Versions;

            lock (Lockee)
            {
                Versions = this.Versions;
            }
            foreach (var Pair in Versions.RangeReversed(Optional <Version> .Empty, v))
            {
                return(Pair.Value);
            }
            return(Allocator());
        }
示例#2
0
        public Optional <KeyValuePair <Version, T> > TryGetLastVersion(ImmutableSortedDictionary <Version, int> Excepts)
        {
            ImmutableSortedDictionary <Version, T> Versions;

            lock (Lockee)
            {
                Versions = this.Versions;
            }
            foreach (var Pair in Versions.RangeReversed(Optional <Version> .Empty, Optional <Version> .Empty))
            {
                if (Excepts.ContainsKey(Pair.Key))
                {
                    continue;
                }
                return(Pair);
            }
            return(Optional <KeyValuePair <Version, T> > .Empty);
        }
示例#3
0
        public T GetVersionContent(Version v, ImmutableSortedDictionary <Version, Unit> Excepts)
        {
            ImmutableSortedDictionary <Version, T> Versions;

            lock (Lockee)
            {
                Versions = this.Versions;
            }
            foreach (var Pair in Versions.RangeReversed(Optional <Version> .Empty, v))
            {
                if (Excepts.ContainsKey(Pair.Key))
                {
                    continue;
                }
                return(Pair.Value);
            }
            return(Allocator());
        }
示例#4
0
        public static void TestRandomAdd()
        {
            var d = new ImmutableSortedDictionary <int, int>();
            var n = 1009; //Prime

            Debug.Assert(!d.ContainsKey(0));
            for (int k = 0; k < n; k += 1)
            {
                var v = (k * 7 + 11) % n;
                d = d.Add(v, v * 2);
            }
            for (int k = 0; k < n; k += 1)
            {
                Debug.Assert(d.ContainsKey(k));
                Debug.Assert(d.TryGetValue(k) == k * 2);
            }
            for (int k = 0; k < n; k += 1)
            {
                var p = d.TryGetPairByIndex(k);
                Debug.Assert(p.Value.Key == k);
                Debug.Assert(p.Value.Value == k * 2);
            }
            Debug.Assert(d.TryGetMin().Value == 0);
            Debug.Assert(d.TryGetMax().Value == (n - 1) * 2);
            Debug.Assert(!d.ContainsKey(-1));
            Debug.Assert(d.Count == n);
            {
                var k = 0;
                foreach (var p in d.Range(Optional <int> .Empty, Optional <int> .Empty))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k += 1;
                }
            }
            {
                var k = n - 1;
                foreach (var p in d.RangeReversed(Optional <int> .Empty, Optional <int> .Empty))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k -= 1;
                }
            }
            {
                var k = 0;
                foreach (var p in d.RangeByIndex(Optional <int> .Empty, Optional <int> .Empty))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k += 1;
                }
            }
            {
                var k = n - 1;
                foreach (var p in d.RangeByIndexReversed(Optional <int> .Empty, Optional <int> .Empty))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k -= 1;
                }
            }
            {
                var k = 100;
                foreach (var p in d.Range(100, 200))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k += 1;
                }
            }
            {
                var k = 200;
                foreach (var p in d.RangeReversed(100, 200))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k -= 1;
                }
            }
            {
                var k = 100;
                foreach (var p in d.RangeByIndex(100, 200))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k += 1;
                }
            }
            {
                var k = 200;
                foreach (var p in d.RangeByIndexReversed(100, 200))
                {
                    Debug.Assert(p.Key == k);
                    Debug.Assert(p.Value == k * 2);
                    k -= 1;
                }
            }
            Debug.Assert(d.RangeCount(100, 200) == 101);
            Debug.Assert(d.RangeCount(0, n - 1) == n);
            Debug.Assert(d.RangeCount(0, Optional <int> .Empty) == n);
            Debug.Assert(d.RangeCount(Optional <int> .Empty, n - 1) == n);
            Debug.Assert(d.RangeCount(Optional <int> .Empty, Optional <int> .Empty) == n);
            var l = d.ToList();

            Debug.Assert(l.Count == n);
            for (int k = 0; k < n; k += 1)
            {
                var p = l[k];
                Debug.Assert(p.Key == k);
                Debug.Assert(p.Value == k * 2);
            }
            for (int k = 0; k < n; k += 1)
            {
                d = d.SetItem(k, k * 3);
            }
            for (int k = 0; k < n; k += 1)
            {
                Debug.Assert(d.ContainsKey(k));
                Debug.Assert(d.TryGetValue(k) == k * 3);
            }
            for (int k = 0; k < n; k += 1)
            {
                var v = (k * 11 + 7) % n;
                d = d.Remove(v);
            }
            Debug.Assert(d.Count == 0);
            var l2 = d.ToList();

            Debug.Assert(l2.Count == 0);
        }