コード例 #1
0
 public ProgressiveList(IEnumerable <T> enumerable, IEqualityComparer <T> comparer)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new List <T>(), comparer)
 {
     // Empty
 }
コード例 #2
0
 protected ProgressiveSet(Progressor <T> progressor, ISet <T> cache, IEqualityComparer <T>?comparer)
     : base(progressor, cache, comparer)
 {
     // Empty
 }
コード例 #3
0
 public ProgressiveLookup(IEnumerable <IGrouping <TKey, T> > enumerable)
     : this(Progressor <IGrouping <TKey, T> > .CreateFromIEnumerable(enumerable), new NullAwareDictionary <TKey, IGrouping <TKey, T> >(), null, null)
 {
     // Empty
 }
コード例 #4
0
 // Note: these constructors uses ExtendedSet because HashSet is not an ISet<T> in .NET 3.5 and base class needs an ISet<T>
 public ProgressiveSet(IEnumerable <T> enumerable)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new HashSetEx <T>(), null)
 {
     // Empty
 }
コード例 #5
0
 public ProgressiveSet(IObservable <T> observable)
     : this(Progressor <T> .CreateFromIObservable(observable), new HashSetEx <T>(), null)
 {
     // Empty
 }
コード例 #6
0
ファイル: ProgressiveSet.cs プロジェクト: lin5/Theraot
 public ProgressiveSet(Progressor <T> wrapped, IEqualityComparer <T> comparer)
     : this(wrapped, new ExtendedSet <T>(comparer), null)
 {
     // Empty
 }
コード例 #7
0
 public ProgressiveCollection(IEnumerable <T> enumerable)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new List <T>(), null)
 {
     // Empty
 }
コード例 #8
0
 public ProgressiveSet(IEnumerable <T> enumerable, IEqualityComparer <T> comparer)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new ExtendedSet <T>(comparer), null)
 {
     // Empty
 }
コード例 #9
0
 public ProgressiveSet(IObservable <T> observable, IEqualityComparer <T> comparer)
     : this(Progressor <T> .CreateFromIObservable(observable), new ExtendedSet <T>(comparer), null)
 {
     // Empty
 }
コード例 #10
0
 // Note: these constructors uses ExtendedSet because HashSet is not an ISet<T> in .NET 3.5 and base class needs an ISet<T>
 public ProgressiveSet(IEnumerable <T> enumerable)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new ExtendedSet <T>(), null)
 {
     // Empty
 }
コード例 #11
0
 public ProgressiveSet(IObservable <T> observable)
     : this(Progressor <T> .CreateFromIObservable(observable), new ExtendedSet <T>(), null)
 {
     // Empty
 }
コード例 #12
0
 internal new static ProgressiveSet <T> Create <TSet>(Progressor <T> progressor, IEqualityComparer <T> comparer)
     where TSet : ISet <T>, new()
 {
     return(new ProgressiveSet <T>(progressor, new TSet(), comparer));
 }
コード例 #13
0
 protected ProgressiveList(Progressor <T> progressor, IList <T> cache, IEqualityComparer <T>?comparer)
     : base(progressor, cache, comparer)
 {
     _cache = cache;
     Cache  = new ReadOnlyCollectionEx <T>(_cache);
 }
コード例 #14
0
 public ProgressiveList(IObservable <T> observable, IEqualityComparer <T> comparer)
     : this(Progressor <T> .CreateFromIObservable(observable), new List <T>(), comparer)
 {
     // Empty
 }
コード例 #15
0
 public ProgressiveList(Progressor <T> wrapped, IEqualityComparer <T> comparer)
     : this(wrapped, new List <T>(), comparer)
 {
     // Empty
 }
コード例 #16
0
ファイル: Progressor.cs プロジェクト: pocketgems/Theraot
        public Progressor(T[] preface, Progressor <T> wrapped)
        {
            if (wrapped == null)
            {
                throw new ArgumentNullException("wrapped");
            }
            if (preface == null)
            {
                throw new ArgumentNullException("preface");
            }

            var control = 0;
            var guard   = 0;
            var index   = -1;

            Predicate <T> newFilter = item => Thread.VolatileRead(ref control) == 0;
            var           buffer    = new SafeQueue <T>();

            wrapped.SubscribeAction
            (
                item =>
            {
                if (newFilter(item))
                {
                    buffer.Add(item);
                }
            }
            );
            _proxy = new ProxyObservable <T>();

            TryTake <T> tryTakeReplacement = (out T value) =>
            {
                Interlocked.Increment(ref control);
                try
                {
                    if (buffer.TryTake(out value) || wrapped.TryTake(out value))
                    {
                        _proxy.OnNext(value);
                        return(true);
                    }
                    else
                    {
                        _done = wrapped._done;
                        return(false);
                    }
                }
                finally
                {
                    Interlocked.Decrement(ref control);
                }
            };

            _tryTake = (out T value) =>
            {
                if (Thread.VolatileRead(ref guard) == 0)
                {
                    var currentIndex = Interlocked.Increment(ref index);
                    if (currentIndex < preface.Length)
                    {
                        value = preface[currentIndex];
                        _proxy.OnNext(value);
                        return(true);
                    }
                    Interlocked.CompareExchange(ref guard, 1, 0);
                }
                if (Interlocked.CompareExchange(ref guard, 2, 1) == 1)
                {
                    _tryTake = tryTakeReplacement;
                    Thread.VolatileWrite(ref guard, 3);
                }
                else
                {
                    ThreadingHelper.SpinWaitUntil(ref guard, 3);
                }
                var tryTake = _tryTake;
                return(tryTake(out value));
            };
        }
コード例 #17
0
ファイル: ProgressiveSet.cs プロジェクト: lin5/Theraot
 public ProgressiveSet(Progressor <T> wrapped)
     : this(wrapped, new ExtendedSet <T>(), null)
 {
     // Empty
 }
コード例 #18
0
ファイル: Progressor.cs プロジェクト: pocketgems/Theraot
        public static Progressor <T> CreatedFilteredConverted <TInput>(Progressor <TInput> wrapped, Predicate <TInput> filter, Converter <TInput, T> converter)
        {
            if (wrapped == null)
            {
                throw new ArgumentNullException("wrapped");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            var control = 0;

            Predicate <TInput> newFilter = item => Thread.VolatileRead(ref control) == 0 && filter(item);
            var buffer = new SafeQueue <T>();
            var proxy  = new ProxyObservable <T>();

            var result = new Progressor <T>(
                (out T value) =>
            {
                Interlocked.Increment(ref control);
                try
                {
                    TInput item;
                    again:
                    if (buffer.TryTake(out value))
                    {
                        proxy.OnNext(value);
                        return(true);
                    }
                    else if (wrapped.TryTake(out item))
                    {
                        if (filter(item))
                        {
                            value = converter(item);
                            proxy.OnNext(value);
                            return(true);
                        }
                        else
                        {
                            goto again;
                        }
                    }
                    value = default(T);
                    return(false);
                }
                finally
                {
                    Interlocked.Decrement(ref control);
                }
            },
                proxy
                );

            wrapped.Subscribe
            (
                new CustomObserver <TInput>
                (
                    () => result._done        = true,
                    exception => result._done = true,
                    item =>
            {
                if (newFilter(item))
                {
                    buffer.Add(converter(item));
                }
            }
                )
            );
            return(result);
        }
コード例 #19
0
 internal static ProgressiveCollection <T> Create <TCollection>(Progressor <T> progressor, IEqualityComparer <T> comparer)
     where TCollection : ICollection <T>, new()
 {
     return(new ProgressiveCollection <T>(progressor, new TCollection(), comparer));
 }
コード例 #20
0
ファイル: Progressor.cs プロジェクト: pocketgems/Theraot
        public static Progressor <T> CreateDistinct(Progressor <T> wrapped)
        {
            if (wrapped == null)
            {
                throw new ArgumentNullException("wrapped");
            }

            var control = 0;

            var           buffer    = new SafeDictionary <T, bool>();
            Predicate <T> newFilter = item => Thread.VolatileRead(ref control) == 0;
            var           proxy     = new ProxyObservable <T>();

            var result = new Progressor <T>(
                (out T value) =>
            {
                Interlocked.Increment(ref control);
                try
                {
                    again:
                    foreach (var item in buffer.Where(item => !item.Value))
                    {
                        value = item.Key;
                        buffer.Set(value, true);
                        proxy.OnNext(value);
                        return(true);
                    }
                    if (wrapped.TryTake(out value))
                    {
                        bool seen;
                        if (!buffer.TryGetValue(value, out seen) || !seen)
                        {
                            buffer.Set(value, true);
                            proxy.OnNext(value);
                            return(true);
                        }
                        else
                        {
                            goto again;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                finally
                {
                    Interlocked.Decrement(ref control);
                }
            },
                proxy
                );

            wrapped.Subscribe
            (
                new CustomObserver <T>
                (
                    () => result._done        = true,
                    exception => result._done = true,
                    item =>
            {
                if (newFilter(item))
                {
                    buffer.TryAdd(item, false);
                }
            }
                )
            );
            return(result);
        }
コード例 #21
0
 public ProgressiveCollection(IObservable <T> observable)
     : this(Progressor <T> .CreateFromIObservable(observable), new List <T>(), null)
 {
     // Empty
 }
コード例 #22
0
ファイル: Progressor.cs プロジェクト: pocketgems/Theraot
        public Progressor(IEnumerable <T> preface, Progressor <T> wrapped)
        {
            if (wrapped == null)
            {
                throw new ArgumentNullException("wrapped");
            }
            if (preface == null)
            {
                throw new ArgumentNullException("preface");
            }
            var enumerator = preface.GetEnumerator();

            if (enumerator == null)
            {
                throw new ArgumentException("preface.GetEnumerator()");
            }

            var control = 0;
            var guard   = 0;

            Predicate <T> newFilter = item => Thread.VolatileRead(ref control) == 0;
            var           buffer    = new SafeQueue <T>();

            wrapped.SubscribeAction
            (
                item =>
            {
                if (newFilter(item))
                {
                    buffer.Add(item);
                }
            }
            );
            _proxy = new ProxyObservable <T>();

            TryTake <T> tryTakeReplacement = (out T value) =>
            {
                Interlocked.Increment(ref control);
                try
                {
                    if (buffer.TryTake(out value) || wrapped.TryTake(out value))
                    {
                        _proxy.OnNext(value);
                        return(true);
                    }
                    else
                    {
                        _done = wrapped._done;
                        return(false);
                    }
                }
                finally
                {
                    Interlocked.Decrement(ref control);
                }
            };

            _tryTake = (out T value) =>
            {
                value = default(T);
                if (Thread.VolatileRead(ref guard) == 0)
                {
                    bool result;
                    // We need a lock, there is no way around it. IEnumerator is just awful. Use another overload if possible.
                    lock (enumerator)
                    {
                        result = enumerator.MoveNext();
                        if (result)
                        {
                            value = enumerator.Current;
                        }
                    }
                    if (result)
                    {
                        _proxy.OnNext(value);
                        return(true);
                    }
                    enumerator.Dispose();
                    Interlocked.CompareExchange(ref guard, 1, 0);
                }
                if (Interlocked.CompareExchange(ref guard, 2, 1) == 1)
                {
                    _tryTake = tryTakeReplacement;
                    Thread.VolatileWrite(ref guard, 3);
                }
                else
                {
                    ThreadingHelper.SpinWaitUntil(ref guard, 3);
                }
                var tryTake = _tryTake;
                return(tryTake(out value));
            };
        }
コード例 #23
0
 public ProgressiveSet(IEnumerable <T> enumerable, IEqualityComparer <T>?comparer)
     : this(Progressor <T> .CreateFromIEnumerable(enumerable), new HashSetEx <T>(comparer), null)
 {
     // Empty
 }
コード例 #24
0
 public ProgressiveCollection(Progressor <T> wrapped)
     : this(wrapped, new HashSet <T>(), null)
 {
     // Empty
 }
コード例 #25
0
 public ProgressiveSet(IObservable <T> observable, IEqualityComparer <T>?comparer)
     : this(Progressor <T> .CreateFromIObservable(observable), new HashSetEx <T>(comparer), null)
 {
     // Empty
 }
コード例 #26
0
 public ProgressiveCollection(Progressor <T> wrapped, IEqualityComparer <T> comparer)
     : this(wrapped, new HashSet <T>(comparer), comparer)
 {
     // Empty
 }
コード例 #27
0
ファイル: EmptyList.cs プロジェクト: pocketgems/Theraot
 private EmptyList()
     : base(BuildEmptyEnumerable())
 {
     Progressor.AsEnumerable().Consume();
 }
コード例 #28
0
 public ProgressiveList(Progressor <T> wrapped)
     : this(wrapped, new List <T>(), null)
 {
     // Empty
 }
コード例 #29
0
 public ProgressiveLookup(IEnumerable <IGrouping <TKey, T> > enumerable, IEqualityComparer <TKey> keyComparer)
     : this(Progressor <IGrouping <TKey, T> > .CreateFromIEnumerable(enumerable), new NullAwareDictionary <TKey, IGrouping <TKey, T> >(keyComparer), keyComparer, null)
 {
     // Empty
 }
コード例 #30
0
 internal static ProgressiveLookup <TKey, T> Create <TGroupingDictionary>(Progressor <IGrouping <TKey, T> > progressor, IEqualityComparer <TKey> keyComparer, IEqualityComparer <T> itemComparer)
     where TGroupingDictionary : IDictionary <TKey, IGrouping <TKey, T> >, new()
 {
     return(new ProgressiveLookup <TKey, T>(progressor, new TGroupingDictionary(), keyComparer, itemComparer));
 }