Exemple #1
0
        private async Task <node> getNodeAt(
            long index, IAccessContext <CSScope> context)
        {
            return(await context.InChild(
                       new CSScope(valueScope : InfiniteIntervalScope.Create(
                                       RWScope.Read, 0, index + 1),
                                   name : $"scope for getNodeAt {index}"),
                       async subContext =>
            {
                await subContext.UntilAvailable(new CSScope(valueScope :
                                                            InfiniteIntervalScope.Create(RWScope.Read, 0, 1),
                                                            name : $"UntilAvailable scope in getNodeAt {index}"));

                node currentNode = state.FirstNode;

                for (long i = 1; i <= index; i++)
                {
                    await subContext.UntilAvailable(new CSScope(
                                                        valueScope: InfiniteIntervalScope.Create(
                                                            RWScope.Read, i, i + 1),
                                                        name: "UntilAvailable scope in " +
                                                        $"getNodeAt {index}"));

                    currentNode = currentNode.Successor;
                }

                return currentNode;
            }));
        }
Exemple #2
0
        private async Task <Tuple <node, int> > getLastNode(
            node startNode, int startIndex, IAccessContext <CSScope> context)
        {
            return(await context.InChild(
                       new CSScope(valueScope : InfiniteIntervalScope.Create(
                                       RWScope.Read, startIndex + 1, null)),
                       async subContext =>
            {
                node currentNode = startNode;
                for (int index = startIndex + 1; ; index++)
                {
                    /* read the node at position index */

                    await subContext.UntilAvailable(new CSScope(valueScope:
                                                                InfiniteIntervalScope.Create(
                                                                    RWScope.Read, index, index + 1)));

                    if (currentNode.Successor == null)
                    {
                        return Tuple.Create(currentNode, index - 1);
                    }
                    currentNode = currentNode.Successor;
                    subContext.RequiredScope = new CSScope(valueScope:
                                                           InfiniteIntervalScope.Create(
                                                               RWScope.Read, index + 1, null));
                }
            }));
        }
Exemple #3
0
 private async Task <Tuple <node, int> > getLastNode(
     IAccessContext <CSScope> context,
     node startNode = null, int startIndex = -1)
 {
     if (startNode == null)
     {
         startIndex = -1;
     }
     return(await context.InChild(new CSScope(
                                      valueScope : InfiniteIntervalScope.Create(
                                          RWScope.Read, startIndex + 1, null),
                                      name : "scope for getLastNode"),
                                  async subContext =>
     {
         if (startNode == null)
         {
             node firstNode = await getFirstNode(subContext);
             if (firstNode == null)
             {
                 return null;
             }
             startNode = firstNode;
             startIndex = 0;
         }
         var t = getLastNode(startNode, startIndex, subContext);
         subContext.Dispose();
         return await t;
     }));
 }
Exemple #4
0
 private async Task incrementNextIndex(
     IAccessContext <enumeratorScope> subContext)
 {
     /* These two statemets (InChild and UntilAvailable)
      * could possibly be combined to a single
      * (extension) method for AccessContext. */
     await subContext.InChild(new enumeratorScope(
                                  nextIndex : RWScope.ReadWrite), async c =>
     {
         await subContext.UntilAvailable();
         nextIndex++;
     });
 }