示例#1
0
    public void Insert(int index, T item)
    {
        if (index < 0 || index > Count)
        {
            throw new ArgumentOutOfRangeException();
        }
        if (this.IsReadOnly)
        {
            throw new NotSupportedException("Deque is readonly.");
        }

        if (index == 0)
        {
            AddBack(item);
            return;
        }

        if (index == Count)
        {
            AddFront(item);
            return;
        }

        int          totalIndex   = GetTotalIndex(index);
        HeadPosition headPosition = new HeadPosition()
        {
            MapPosition     = totalIndex / DATABLOCK_LENGTH,
            DataBlockOffset = (totalIndex % DATABLOCK_LENGTH)
        };

        if (headPosition - RearHead < FrontHead - headPosition)
        {
            T last = QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset];
            QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset] = item;
            for (var head = headPosition.IncNew();
                 head != FrontHead;
                 head.Inc())
            {
                T temp = QueueMap[head.MapPosition][head.DataBlockOffset];
                QueueMap[head.MapPosition][head.DataBlockOffset] = last;
                last = temp;
            }
            AddFront(last);
        }
        else
        {
            headPosition.Dec();
            T last = QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset];
            QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset] = item;
            for (var head = headPosition.DecNew();
                 head != RearHead;
                 head.Dec())
            {
                T temp = QueueMap[head.MapPosition][head.DataBlockOffset];
                QueueMap[head.MapPosition][head.DataBlockOffset] = last;
                last = temp;
            }
            AddBack(last);
        }
    }
示例#2
0
        void TrackData(float t, double yaw01, double pitch01, byte fov)
        {
            int idx = (int)Math.Floor(t * precision);

            lock (data)
            {
                // add new element at end (and return)
                if (data.Count == idx)
                {
                    data.Add(new HeadPosition(yaw01, pitch01, fov));
                    return;
                }

                // no space for element - need to resize
                else if (idx >= data.Count)
                {
                    if (idx > data.Capacity)
                    {
                        data.Capacity = idx + 1;
                    }
                    data.AddRange(Enumerable.Repeat <HeadPosition>(new HeadPosition(), data.Capacity - data.Count));
                }

                // finally add the element
                //if (data[idx] != null)
                //{
                //    // TODO: integrate?
                //}
                data[idx] = new HeadPosition(yaw01, pitch01, fov);
            }
        }
示例#3
0
        /// <summary>
        /// замена символа
        /// длина команды - динамическая
        /// </summary>
        /// <param name="one">заменяемый символ</param>
        /// <param name="two">заменяющий символ</param>
        /// <param name="pos">позиция головки</param>
        /// <returns>длину команды</returns>
        public void Replace(string one, string two, string com = null, HeadPosition pos = HeadPosition.End)
        {
            int index = prog.Count + 1;

            if (pos == HeadPosition.End)
            {
                // остановка в начале замененного символа
                for (int i = two.Length - 1; i >= 0; i--)
                {
                    //Console.WriteLine(one + " " + two);
                    if (one[i] == two[i])
                    {
                        string[] s = PostCommands.CreateLeftCommand(++index, com);
                        prog.Add(s);
                    }
                    else
                    if (one[i] != two[i] && one[i] == 'V')
                    {
                        string[] s  = PostCommands.CreateClearCommand(++index, com);
                        string[] s2 = PostCommands.CreateLeftCommand(++index, com);
                        prog.Add(s); prog.Add(s2);
                    }
                    else
                    {
                        string[] s  = PostCommands.CreateTagCommand(++index, com);
                        string[] s2 = PostCommands.CreateLeftCommand(++index, com);
                        prog.Add(s); prog.Add(s2);
                    }
                }
            }
            else if (pos == HeadPosition.Start)
            {
                // остановка в начале следующего символа
                for (int i = 0; i < two.Length; i++)
                {
                    if (one[i] == two[i])
                    {
                        string[] s = PostCommands.CreateRightCommand(++index, com);
                        prog.Add(s);
                    }
                    else
                    if (one[i] != two[i] && one[i] == 'V')
                    {
                        string[] s  = PostCommands.CreateClearCommand(++index, com);
                        string[] s2 = PostCommands.CreateRightCommand(++index, com);
                        prog.Add(s); prog.Add(s2);
                    }
                    else
                    {
                        string[] s  = PostCommands.CreateTagCommand(++index, com);
                        string[] s2 = PostCommands.CreateRightCommand(++index, com);
                        prog.Add(s); prog.Add(s2);
                    }
                }
            }

            string[] s1 = PostCommands.CreateRightCommand(++index); // TODO
            prog.Add(s1);
        }
示例#4
0
 public static Command CreateAddRecordingCommand(int seq, HeadPosition pos)
 {
     return(new Command
     {
         seq = seq,
         command = AddRecordingCommand,
         position = pos.position,
         eularAngle = pos.eularAngle,
     });
 }
示例#5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hash = 17;
         hash = hash * 23 + IsStartSymbol.GetHashCode();
         hash = hash * 23 + HeadPosition.GetHashCode();
         for (var i = 0; i < Production.Length; i++)
         {
             hash = hash * 23 + Production[i].GetHashCode();
         }
         return(hash);
     }
 }
示例#6
0
    public void RemoveAt(int index)
    {
        if (index < 0 || index >= Count)
        {
            throw new ArgumentOutOfRangeException();
        }

        if (index == 0)
        {
            GetBack();
            return;
        }

        if (index == Count - 1)
        {
            GetFront();
            return;
        }

        int          totalIndex   = GetTotalIndex(index);
        HeadPosition headPosition = new HeadPosition()
        {
            MapPosition     = totalIndex / DATABLOCK_LENGTH,
            DataBlockOffset = (totalIndex % DATABLOCK_LENGTH)
        };

        if (headPosition - RearHead < FrontHead - headPosition)
        {
            for (var head = headPosition.IncNew();
                 head != FrontHead;
                 head.Inc())
            {
                QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset] = QueueMap[head.MapPosition][head.DataBlockOffset];
                headPosition.Inc();
            }
            GetFront();
        }
        else
        {
            for (var head = headPosition.DecNew();
                 head != RearHead;
                 head.Dec())
            {
                QueueMap[headPosition.MapPosition][headPosition.DataBlockOffset] = QueueMap[head.MapPosition][head.DataBlockOffset];
                headPosition.Dec();
            }
            GetBack();
        }
    }
示例#7
0
 public void Clear()
 {
     Size      = DEFAULT_MAP_SIZE;
     Count     = 0;
     MapCount  = 0;
     QueueMap  = new T[DEFAULT_MAP_SIZE][];
     FrontHead = new HeadPosition()
     {
         MapPosition = (Size / 2), DataBlockOffset = (DATABLOCK_LENGTH / 2)
     };
     RearHead = new HeadPosition()
     {
         MapPosition = (Size / 2), DataBlockOffset = (DATABLOCK_LENGTH / 2) - 1
     };
 }
示例#8
0
        private string IsIndefinite(ITmRunBase tm)
        {
            if (tm.Tape is ISimpleTape)               // todo what about MM?
            {
                var tape = tm.Tape as ISimpleTape;

                HeadPosition atEnd = tm.Tape.IsAtEnd;
                if (atEnd != HeadPosition.Neither && tape.ReadSingle() == 0)
                {
                    var closure = tm.Q.TransitiveClosure(
                        t => t != null && t.Read == 0,
                        t => t.Direction != (int)atEnd);
                    if (closure != null && !closure.Contains(tm.Definition.Qr))
                    {
                        DebugStats_Indefinite_TrivialRunner++;
                        return(""
                               + "Runs indefinitely. Reason: "
                               + "We're at the end of the tape and the tape is already 0. "
                               + "All further transitions reached via input 0 only direct further away. "
                               + "But those nodes do not contain the exit. "
                               + "Thus we're certainly in an infinite run.");
                    }
                }
            }

            ulong nTape = tm.Tape.TotalTapeLength + 1;

            if (nTape < 30)
            {
                int   usedStates    = tm.Definition.Q.Count(q => q.Value.Sources.Any());
                ulong requiredSpace = (ulong)usedStates * nTape * (ulong)(2 << (int)nTape);
                if (tm.Shifts > requiredSpace)
                {
                    DebugStats_Indefinite_SpaceTooSmall++;
                    return(""
                           + "Runs indefinitely. Reason: "
                           + "The tape used is too small to hold as many different configurations as there have been shifts. "
                           + "Used states: " + usedStates + ", required space: " + requiredSpace + ", shifts: " + tm.Shifts + " "
                           + "(This can only be used for small tapes.)");
                }
            }

            return(null);
        }
示例#9
0
        internal static Boolean QueryHeadPositionINT(IntPtr instance, out HeadPosition outHeadPosition)
        {
            outHeadPosition = new HeadPosition();

            return(PXCMFaceData_PoseData_QueryHeadPosition(instance, outHeadPosition));
        }
示例#10
0
 internal static extern Boolean PXCMFaceData_PoseData_QueryHeadPosition(IntPtr instance, [Out] HeadPosition outHeadPosition);
示例#11
0
        /// <summary>
        /// замена символа
        /// длина команды - динамическая
        /// </summary>
        /// <param name="one">заменяемый символ</param>
        /// <param name="two">заменяющий символ</param>
        /// <param name="pos">позиция головки</param>
        /// <returns>длину команды</returns>
        public void Replace(string one, string two, string com = null, HeadPosition pos = HeadPosition.End)
        {
            int index = prog.Count + 1;

               if(pos == HeadPosition.End)
               {
               // остановка в начале замененного символа
               for(int i=two.Length-1; i>=0; i--)
               {
                   //Console.WriteLine(one + " " + two);
                   if(one[i]==two[i])
                   {
                       string[] s = PostCommands.CreateLeftCommand(++index, com);
                       prog.Add(s);
                   } else
                       if(one[i]!=two[i] && one[i]=='V')
                   {
                       string[] s = PostCommands.CreateClearCommand(++index, com);
                       string[] s2 = PostCommands.CreateLeftCommand(++index, com);
                       prog.Add(s); prog.Add(s2);
                   } else
                       {
                           string[] s = PostCommands.CreateTagCommand(++index, com);
                           string[] s2 = PostCommands.CreateLeftCommand(++index, com);
                           prog.Add(s); prog.Add(s2);
                       }
               }
               } else if(pos == HeadPosition.Start)
               {
               // остановка в начале следующего символа
               for (int i = 0; i < two.Length; i++)
               {
                   if (one[i] == two[i])
                   {
                       string[] s = PostCommands.CreateRightCommand(++index, com);
                       prog.Add(s);
                   }
                   else
                       if (one[i] != two[i] && one[i] == 'V')
                       {
                           string[] s = PostCommands.CreateClearCommand(++index, com);
                           string[] s2 = PostCommands.CreateRightCommand(++index, com);
                           prog.Add(s); prog.Add(s2);
                       }
                       else
                       {
                           string[] s = PostCommands.CreateTagCommand(++index,com);
                           string[] s2 = PostCommands.CreateRightCommand(++index,com);
                           prog.Add(s); prog.Add(s2);
                       }
               }
               }

               string[] s1 = PostCommands.CreateRightCommand(++index); // TODO
               prog.Add(s1);
        }
示例#12
0
 private void AllocateNewDataBlock(HeadPosition where)
 {
     MapCount++;
     QueueMap[where.MapPosition] = new T[DATABLOCK_LENGTH];
 }
示例#13
0
 /*
     * Assigns the head position to outHeadPosition.
     * Returns true if data and parameters exist, false otherwise.
 */
 public Boolean QueryHeadPosition(out HeadPosition outHeadPosition)
 {
     return QueryHeadPositionINT(instance, out outHeadPosition);
 }
示例#14
0
 /*
  * Assigns the head position to outHeadPosition.
  * Returns true if data and parameters exist, false otherwise.
  */
 public Boolean QueryHeadPosition(out HeadPosition outHeadPosition)
 {
     return(QueryHeadPositionINT(instance, out outHeadPosition));
 }
示例#15
0
 internal static Boolean QueryHeadPositionINT(IntPtr instance, out HeadPosition outHeadPosition)
 {
     outHeadPosition = new HeadPosition();
     return PXCMFaceData_PoseData_QueryHeadPosition(instance, outHeadPosition);
 }