コード例 #1
0
        public RemoteChunksSeries(long mapId,
                                  IKeyComparer <K> comparer,
                                                                                // mapId, current map version => map with chunk keys and versions
                                  Func <long, long, Task <SortedMap <long, SeriesChunk> > > remoteKeysLoader,
                                                                                // mapId, chunkKey => deserialied chunk
                                  Func <long, long, Task <SeriesChunk> > remoteLoader,
                                                                                // mapId, chunkKey, deserialied chunk => whole map version
                                  Func <SeriesChunk, Task <long> > remoteSaver, // TODO corresponding updates
                                                                                // mapId, chunkKey, direction => whole map version
                                  Func <long, long, long, Lookup, Task <long> > remoteRemover,
                                  long version,
                                  bool readOnly = false)
        {
            _mapId            = mapId;
            _comparer         = comparer;
            _remoteKeysLoader = remoteKeysLoader;
            _remoteLoader     = remoteLoader;
            _remoteSaver      = remoteSaver;
            _remoteRemover    = remoteRemover;
            _readOnly         = readOnly;

            var renewedKeys = _remoteKeysLoader(_mapId, 0).Result;
            var sm          = renewedKeys.Map((k, ch) => new LazyValue(k, ch.Count, ch.Version, this)).ToSortedMap();

            sm.IsSynchronized = true;
            _chunksCache      = sm;
            var maxChunkVersion = _chunksCache.Values.Max(x => x.ChunkVersion);

            if (maxChunkVersion != version)
            {
                Trace.TraceWarning("Inconsistent series version in chunks and series definition.");
            }
            _chunksCache.Version = Math.Max(version, maxChunkVersion);
        }
コード例 #2
0
 public ProjectValuesWrapper(IOrderedMap <K, Vsrc> innerMap,
                             Func <Vsrc, Vdest> srcToDest, Func <Vdest, Vsrc> destToSrc)
 {
     _innerMap  = innerMap;
     _srcToDest = srcToDest;
     _destToSrc = destToSrc;
 }
コード例 #3
0
ファイル: StochasticTestMap.cs プロジェクト: fsgeek/TreeLib
        public override bool Do(int seed, StochasticControls control)
        {
            IOrderedMap <int, float>[] collections = new IOrderedMap <int, float>[]
            {
                new ReferenceMap <int, float>(), // must be first

                new SplayTreeMap <int, float>(),
                new SplayTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new SplayTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new SplayTreeArrayList <KeyValue <int, float> >()),

                new RedBlackTreeMap <int, float>(),
                new RedBlackTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new RedBlackTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new RedBlackTreeArrayList <KeyValue <int, float> >()),

                new AVLTreeMap <int, float>(),
                new AVLTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new AVLTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new AVLTreeArrayList <KeyValue <int, float> >()),
            };

            Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >[] actions = new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >[]
            {
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), ContainsKeyAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200, 200), SetOrAddValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200 - 50, 200 + 50), TryAddAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(300, 300), TryRemoveAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), TryGetValueAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), TrySetValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200 - 50, 200 + 50), AddAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(300, 300), RemoveAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), GetValueAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), SetValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(50, 50), ConditionalAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), LeastAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), GreatestAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestLessOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestLessAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestGreaterOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestGreaterAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(50, 50), EnumerateAction),
            };

            return(StochasticDriver(
                       "Map Stochastic Test",
                       seed,
                       control,
                       collections,
                       actions,
                       delegate(IOrderedMap <int, float> _collection) { return _collection.Count; },
                       delegate(IOrderedMap <int, float>[] _collections) { Validate <int, float>(_collections); }));
        }
コード例 #4
0
 private static void LoadTree(IOrderedMap <int, int> tree, int count, int[] keys)
 {
     for (int i = 0; i < count; i++)
     {
         int key = keys[i];
         tree.Add(key, key);
     }
 }
コード例 #5
0
        public override void UntimedPrepare()
        {
            if (preparation == null)
            {
                preparation = new Preparation(count);
            }

            tree = makeTree(count);
        }
コード例 #6
0
 private void EnumerateCore(IOrderedMap <int, float> map, int count, bool fast)
 {
     for (int i = 0; i < count; i++)
     {
         map.Add(i, i);
     }
     foreach (EntryMap <int, float> entry in fast ? map.GetFastEnumerable() : map.GetRobustEnumerable())
     {
     }
 }
コード例 #7
0
        private static void UnloadTree(IOrderedMap <int, int> tree, int?count, int[] keys)
        {
            int i = 0;

            while ((count.HasValue && (i < count.Value)) || (!count.HasValue && (tree.Count != 0)))
            {
                int key = keys[i];
                tree.NearestGreaterOrEqual(key, out key);
                tree.Remove(key);
                i++;
            }
        }
コード例 #8
0
 private void BasicMapCore(IOrderedMap <int, float> map, int count)
 {
     for (int j = 0; j < 2; j++)
     {
         for (int i = 0; i < count; i++)
         {
             map.Add(i, i);
         }
         for (int i = 0; i < count; i++)
         {
             map.Remove(i);
         }
     }
 }
コード例 #9
0
 private void ConditionalMapCore(IOrderedMap <int, float> map, int count)
 {
     for (int j = 0; j < 2; j++)
     {
         for (int i = 0; i < count; i++)
         {
             map.ConditionalSetOrAdd(i, _ConditionalSetOrAdd);
         }
         for (int i = 0; i < count; i++)
         {
             map.ConditionalSetOrRemove(i, _ConditionalSetOrRemove);
         }
     }
 }
コード例 #10
0
        public void CouldCompleteObserver(IOrderedMap <int, int> map)
        {
            var subscriber = new SumValuesObserver();
            var series     = map as Series <int, int>;
            var cursor     = (series + series).GetCursor();

            cursor.Source.Subscribe(subscriber);
            var expectedSum = 0;

            for (int i = 0; i < 10; i++)
            {
                map.Add(i, i);
                expectedSum += i;
            }

            Assert.IsFalse(subscriber.IsCompleted);
            map.Complete();
            Thread.Sleep(100);
            Assert.IsTrue(subscriber.IsCompleted);
            Thread.Sleep(1000);
            Assert.AreEqual(expectedSum * 2, subscriber.Sum);
        }
コード例 #11
0
ファイル: UnitTestAllocation.cs プロジェクト: fsgeek/TreeLib
 public AllocTestMap(IOrderedMap <int, float> actual)
 {
     this.actual = actual;
 }
コード例 #12
0
 public ZonedSeries(IOrderedMap <DateTime, V> map, string originalTimeZone)
 {
     _map = map;
     _tz  = originalTimeZone;
 }
コード例 #13
0
ファイル: CursorSeries.cs プロジェクト: s952163/Spreads
 /// <summary>
 /// Projects values from source to destination and back
 /// </summary>
 public static IPersistentOrderedMap <K, VDest> BiMap <K, VSrc, VDest>(this IOrderedMap <K, VSrc> innerMap,
                                                                       Func <VSrc, VDest> srcToDest, Func <VDest, VSrc> destToSrc)
 {
     return(new ProjectValuesWrapper <K, VSrc, VDest>(innerMap, srcToDest, destToSrc));
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: fsgeek/TreeLib
 public override void Do(IOrderedMap <int, bool> tree, List <KeyValuePair <int, bool> > treeAnalog)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: fsgeek/TreeLib
 public override void Do(IOrderedMap <int, bool> tree)
 {
     throw new NotImplementedException();
 }