Пример #1
0
            protected override void OnExecute(Tangle <T> tangle, out NoneType result)
            {
                var keys = Keys;

                var count = GetCountFast(Keys);

                if (!count.HasValue)
                {
                    var array = Keys.ToArray();
                    keys  = array;
                    count = array.Length;
                }

                Parallel.ForEach(
                    keys, (rawKey) => {
                    T value;
                    if (tangle.InternalGet(KeyConverter(rawKey), out value))
                    {
                        Function(rawKey, value);
                    }
                }
                    );

                result = NoneType.None;
            }
Пример #2
0
            protected override void OnExecute(Tangle <T> tangle, out TMapped result)
            {
                var keys = Keys;

                var count = GetCountFast(Keys);

                if (!count.HasValue)
                {
                    var array = Keys.ToArray();
                    keys  = array;
                    count = array.Length;
                }

                Func <TKey, TMapped> adapter = (rawKey) => {
                    T value;
                    if (tangle.InternalGet(KeyConverter(rawKey), out value))
                    {
                        return(Map(rawKey, value));
                    }

                    return(DefaultValue);
                };

                result =
                    (from k in keys.AsParallel().AsOrdered() select adapter(k))
                    .Aggregate(InitialValue, Reduce);
            }
Пример #3
0
            protected override void OnExecute(Tangle <T> tangle, out T[] result)
            {
                var keys = Keys;

                var count = GetCountFast(Keys);

                if (!count.HasValue)
                {
                    var array = Keys.ToArray();
                    keys  = array;
                    count = array.Length;
                }

                var results = new T[count.Value];

                Parallel.ForEach(
                    keys, (rawKey, loopState, i) => {
                    T value;
                    if (tangle.InternalGet(KeyConverter(rawKey), out value))
                    {
                        results[i] = value;
                    }
                    else
                    {
                        results[i] = default(T);
                    }
                }
                    );

                result = results;
            }
Пример #4
0
 protected override void OnExecute(Tangle <T> tangle, out T result)
 {
     if (!tangle.InternalGet(Key, out result))
     {
         Fail(new KeyNotFoundException(Key));
     }
 }
Пример #5
0
            protected override unsafe void OnExecute(Tangle <TValue> tangle, out TValue[] result)
            {
                long nodeIndex;
                uint valueIndex;

                var matchedKeys = new HashSet <TangleKey>();

                foreach (var key in Keys)
                {
                    if (Index.BTree.FindKey(key, false, out nodeIndex, out valueIndex))
                    {
                        HashSet <TangleKey> keys;
                        using (var range = Index.BTree.AccessValue(nodeIndex, valueIndex))
                            Index.BTree.ReadData((BTreeValue *)range.Pointer, Index <TIndexKey, TValue> .DeserializeKeys, out keys);

                        matchedKeys.UnionWith(keys);
                    }
                }

                // Maybe we should throw for missing keys or values?

                var resultArray = new TValue[matchedKeys.Count];

                Parallel.ForEach(matchedKeys, (key, loopState, i) => {
                    tangle.InternalGet(key, out resultArray[i]);
                });

                result = resultArray;
            }
Пример #6
0
            protected override unsafe void OnExecute(Tangle <TValue> tangle, out TValue[] result)
            {
                long nodeIndex;
                uint valueIndex;

                result = null;
                if (Index.BTree.FindKey(Key, false, out nodeIndex, out valueIndex))
                {
                    HashSet <TangleKey> keys;
                    using (var range = Index.BTree.AccessValue(nodeIndex, valueIndex))
                        Index.BTree.ReadData((BTreeValue *)range.Pointer, Index <TIndexKey, TValue> .DeserializeKeys, out keys);

                    result = new TValue[keys.Count];
                    int i = 0;
                    foreach (var key in keys)
                    {
                        tangle.InternalGet(key, out result[i]);
                        i += 1;
                    }
                }
                else
                {
                    Fail(new KeyNotFoundException(Key));
                }
            }
Пример #7
0
            protected override void OnExecute(Tangle <T> tangle, out T[] result)
            {
                var keys = Keys;

                var count = GetCountFast(Keys);

                if (!count.HasValue)
                {
                    var array = Keys.ToArray();
                    keys  = array;
                    count = array.Length;
                }

                var results = new T[count.Value];

                foreach (var barrier in Barriers)
                {
                    barrier.ReadyForJoinSignal.Wait();
                }

                Parallel.ForEach(
                    keys, (rawKey, loopState, i) => {
                    T value;
                    var key = KeyConverter(rawKey);

                    results[i] = default(T);
                    if (tangle.InternalGet(key, out value))
                    {
                        results[i] = value;
                    }
                    else
                    {
                        foreach (var cascade in Cascades)
                        {
                            if (cascade.InternalGet(key, out value))
                            {
                                results[i] = value;
                                break;
                            }
                        }
                    }
                }
                    );

                result = results;

                foreach (var barrier in Barriers)
                {
                    barrier.JoinCompleteSignal.Set();
                }
            }
Пример #8
0
            protected override void OnExecute(Tangle <T> tangle, out TOut[] result)
            {
                var keys = Keys;

                var count = GetCountFast(Keys);

                if (!count.HasValue)
                {
                    var array = Keys.ToArray();
                    keys  = array;
                    count = array.Length;
                }

                var results = new TOut[count.Value];

                if (RightBarrier != null)
                {
                    RightBarrier.ReadyForJoinSignal.Wait();
                }

                Parallel.ForEach(
                    keys, (leftKey, loopState, i) => {
                    T leftValue;
                    TRight rightValue;

                    if (!tangle.InternalGet(LeftKeyConverter(leftKey), out leftValue))
                    {
                        return;
                    }

                    var rightKey = KeySelector(leftKey, ref leftValue);
                    if (!Right.InternalGet(RightKeyConverter(rightKey), out rightValue))
                    {
                        return;
                    }

                    results[i] = ValueSelector(leftKey, ref leftValue, rightKey, ref rightValue);
                }
                    );

                result = results;

                if (RightBarrier != null)
                {
                    RightBarrier.JoinCompleteSignal.Set();
                }
            }
Пример #9
0
            protected override unsafe void OnExecute(Tangle <TValue> tangle, out TValue result)
            {
                long nodeIndex;
                uint valueIndex;

                if (Index.BTree.FindKey(Key, false, out nodeIndex, out valueIndex))
                {
                    HashSet <TangleKey> keys;

                    using (var range = Index.BTree.AccessValue(nodeIndex, valueIndex))
                        Index.BTree.ReadData((BTreeValue *)range.Pointer, Index <TIndexKey, TValue> .DeserializeKeys, out keys);

                    var firstKey = keys.First();
                    if (!tangle.InternalGet(firstKey, out result))
                    {
                        Fail(new KeyNotFoundException(firstKey));
                    }
                }
                else
                {
                    result = default(TValue);
                    Fail(new KeyNotFoundException(Key));
                }
            }