Beispiel #1
0
        static void Main(string[] args)
        {
            //初始化队列
            var queue = new CircleQueue <string>(9);

            Console.WriteLine($"泛型当前队列长度为{queue.Size}");
            Console.WriteLine("向长度为9的入队10个字符串\n");
            for (int i = 1; i <= 10; i++)
            {
                if (queue.IsFull)
                {
                    Console.Write("队列已满“10string”入队失败,");
                    break;
                }
                if (queue.AddQueue($"string{i}"))
                {
                    Console.Write($"string{i}\t");
                }
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\t");


            Console.WriteLine("出队5个字符串...\n");
            for (int i = 1; i <= 5; i++)
            {
                Console.Write($"{queue.GetQueue()}\t");
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\n");
        }
Beispiel #2
0
 public Form1()
 {
     InitializeComponent();
     circleQueue     = new CircleQueue <int>(10);
     _timer          = new System.Timers.Timer();
     _timer.Interval = 100;
     _timer.Elapsed += ShowQueueInfo;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            //初始化队列
            var queue = new CircleQueue(9);

            Console.WriteLine($"当前队列长度为{queue.Size}");
            Console.WriteLine("向长度为9的入队10个数字\n");
            for (int i = 1; i <= 10; i++)
            {
                if (queue.IsFull)
                {
                    Console.Write("队列已满“10”入队失败,");
                    break;
                }
                if (queue.AddQueue(i))
                {
                    Console.Write($"{i}\t");
                }
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\t");

            //-----------------------------------------------------------

            Console.WriteLine("出队5个数字...\n");
            for (int i = 1; i <= 5; i++)
            {
                Console.Write($"{queue.GetQueue()}\t");
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\n");

            //-----------------------------------------------------------

            Console.WriteLine("向队列队列插入10个数字...\n");
            for (int i = 1; i <= 10; i++)
            {
                if (queue.IsFull)
                {
                    Console.Write("队列已满“6 7 8 9 10”入队失败,");
                    break;
                }
                if (queue.AddQueue(i))
                {
                    Console.Write($"{i}\t");
                }
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\n");

            //-----------------------------------------------------------

            Console.WriteLine($"打印当前队列");
            var size = queue.Size;

            for (int i = 0; i < size; i++)
            {
                Console.Write($"{queue.GetQueue()}\t");
            }
            Console.WriteLine($"当前队列长度为{queue.Size}\n");
        }
Beispiel #4
0
 public void Initialize(int capacity)
 {
     this.queueOfWork       = new CircleQueue <T>(capacity);
     this.agileCycleEngines = new AgileCycleEngine[this.workerThreadCount];
     for (int i = 0; i < this.agileCycleEngines.Length; i++)
     {
         this.agileCycleEngines[i] = new AgileCycleEngine(this);
         this.agileCycleEngines[i].DetectSpanInSecs = 0;
     }
 }
        public void ThreeElementsQueueAfterAddThreeElementIsFull()
        {
            var queue = new CircleQueue <double>(capacity: 3);

            queue.SaveValue(3.3);
            queue.SaveValue(5);
            queue.SaveValue(10.8);

            Assert.IsTrue(queue.IsFull);
        }
Beispiel #6
0
        public void QueueTest_當存入輸入時_IsEmpty為false()
        {
            var expect = new int[] { 24, 12, 16, 22 };

            var queue = new CircleQueue <int>();

            foreach (var i in expect)
            {
                queue.Enqueue(i);
            }

            Assert.IsFalse(queue.IsEmpty);
        }
Beispiel #7
0
 /// <summary>
 /// 엘리베이터 감시반에서 통합 서버로 보내는 정보 프로토콜 STX, ETX 체크
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="queue"></param>
 /// <returns></returns>
 private bool StatusNotificationCheck(object sender, CircleQueue queue)
 {
     //Header Check
     if (queue.Buffer[(queue.Sp + 0 + queue.Size) % queue.Size] != (byte)'S' && queue.Buffer[(queue.Sp + 0 + queue.Size) % queue.Size] != (byte)'E')
     {
         return(false);           // Header Check
     }
     //Tail Check
     if (queue.Buffer[(queue.Sp - 1 + queue.Size) % queue.Size] != (byte)'E')
     {
         return(false);
     }
     return(true);
 }
        public void HasFirstElementAddToQueueIsFirstRead()
        {
            var queue = new CircleQueue <double>(capacity: 3);

            var value1 = 8.8;
            var value2 = 5.1;

            queue.SaveValue(value1);
            queue.SaveValue(value2);


            Assert.AreEqual(value1, queue.ReadValue());
            Assert.AreEqual(value2, queue.ReadValue());
            Assert.IsTrue(queue.IsEmpty);
        }
        public void HasOverwriteValueWhenCapacityIsExceed()
        {
            var queue = new CircleQueue <double>(capacity: 3);

            var values = new[] { 1.8, 3.5, 5.1, 7.6, 9.1, 11.0 };

            foreach (var item in values)
            {
                queue.SaveValue(item);
            }

            Assert.IsTrue(queue.IsFull);
            Assert.AreEqual(values[3], queue.ReadValue());
            Assert.AreEqual(values[4], queue.ReadValue());
            Assert.AreEqual(values[5], queue.ReadValue());
            Assert.IsTrue(queue.IsEmpty);
        }
Beispiel #10
0
        private void CompareMatch <T>(IEnumerable <T> expect)
        {
            var queue = new CircleQueue <T>();

            foreach (var i in expect)
            {
                queue.Enqueue(i);
            }

            var actual = new List <T>();

            while (!queue.IsEmpty)
            {
                var i = queue.Dequeue();
                actual.Add(i);
            }

            expect.ToExpectedObject().ShouldMatch(actual);
        }
Beispiel #11
0
 /// <summary>
 /// 序列化后进行Gzip压缩
 /// </summary>
 /// <param name="path"></param>
 /// <param name="cq"></param>
 public void LogDataSerlializerAndCompress(string path, CircleQueue <LogTrackFunc> cq)
 {
     if (cq != null)
     {
         int length = cq.QueueLength();
         if (length != 0)
         {
             cq.ResetCur();
             List <LogTrackFunc> ltfList = new List <LogTrackFunc>();
             for (int i = 0; i < length; i++)
             {
                 ltfList.Add(cq.GetNext());
             }
             using (MemoryStream ms = new MemoryStream())
             {
                 using (var gzipStream = new GZipOutputStream(File.Open(path, FileMode.Create)))
                 {
                     //将数据序列化后写至内存流中
                     ProtoBuf.Serializer.Serialize <List <LogTrackFunc> >(ms, ltfList);
                     // 重置内存流的读写位置(此步很关键)
                     ms.Position = 0;
                     //定义缓冲区大小
                     int buffersize = 1024;
                     //创建缓冲数据
                     byte[] FileData = new byte[buffersize];
                     //循环读写
                     while (buffersize > 0)
                     {
                         //先将内存流中的数据读到缓冲区中
                         buffersize = ms.Read(FileData, 0, buffersize);
                         //把缓冲区中数据写入到文件流中
                         gzipStream.Write(FileData, 0, buffersize);//写入压缩文件
                     }
                 }
             }
         }
     }
 }
Beispiel #12
0
    /*
     * /// <summary>
     * /// 在线写入可读性日志(id和Args)
     * /// </summary>
     * /// <param name="path">写入文件的路径</param>
     * /// <param name="cq">内存中存储的近60帧的循环队列</param>
     * public void WriteLogDataToLocalIdWithArgs(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq != null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           List<int> idList = new List<int>();
     *           List<int> argList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   idList.AddRange(ltf.Items);
     *                   argList.AddRange(ltf.Args);
     *               }
     *           }
     *           string strMsg = JsonHandler.OutputAllMes(idList, argList, path);
     *           using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               byte[] by = System.Text.Encoding.UTF8.GetBytes(strMsg);
     *               fs.Write(by, 0, by.Length);
     *           }
     *       }
     *   }
     * }
     *
     * /// <summary>
     * /// 在线写入可读性日志(id)
     * /// </summary>
     * /// <param name="path">写入文件的路径</param>
     * /// <param name="cq">内存中存储的近60帧的循环队列</param>
     * public void WriteLogDataToLocalId(string logPdbPath, string logSavePath, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq != null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           List<int> idList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   idList.AddRange(ltf.Items);
     *               }
     *           }
     *           string strMsg = JsonHandler.OutputAllMes(idList, logPdbPath);
     *           using (FileStream fs = new FileStream(logSavePath, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               byte[] by = System.Text.Encoding.UTF8.GetBytes(strMsg);
     *               fs.Write(by, 0, by.Length);
     *           }
     *       }
     *   }
     * }
     *
     * /// <summary>
     * /// 在线写入可读性日志(id和帧数)
     * /// </summary>
     * /// <param name="logPdbPath"></param>
     * /// <param name="logSavePath"></param>
     * /// <param name="cq"></param>
     * public void WriteLogDataToLocalIdAndFrame(string logPdbPath, string logSavePath, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq != null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           List<int> idList = new List<int>();
     *           List<int> frameList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   idList.AddRange(ltf.Items);
     *                   frameList.Add(ltf.FrameIndex);
     *               }
     *           }
     *           string strMsg = JsonHandler.OutputAllMes(idList, frameList, logPdbPath);
     *           using (FileStream fs = new FileStream(logSavePath, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               byte[] by = System.Text.Encoding.UTF8.GetBytes(strMsg);
     *               fs.Write(by, 0, by.Length);
     *           }
     *       }
     *   }
     * }
     *
     *
     * /// <summary>
     * /// 在线写入日志数据(id和Args)
     * /// </summary>
     * /// <param name="path">文件写入的路径</param>
     * /// <param name="cq">保存近60帧数据的循环队列</param>
     * public void WriteLogDataIdWithArgs(string path,CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq!=null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           List<int> idList = new List<int>();
     *           List<int> argList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   idList.AddRange(ltf.Items);
     *                   argList.AddRange(ltf.Args);
     *               }
     *           }
     *           using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               BinaryWriter sw = new BinaryWriter(fs);
     *               for (int i = 0; i < idList.Count; i++)
     *               {
     *                   sw.Write(idList[i]);
     *               }
     *               //分隔符
     *               sw.Write(int.MaxValue);
     *               for (int i = 0; i < argList.Count; i++)
     *               {
     *                   sw.Write(argList[i]);
     *               }
     *               sw.Close();
     *           }
     *       }
     *   }
     * }
     *
     * /// <summary>
     * /// 在线写入日志数据(id)
     * /// </summary>
     * /// <param name="path">文件写入的路径</param>
     * /// <param name="cq">保存近60帧数据的循环队列</param>
     * public void WriteLogDataId(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq != null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           List<int> idList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   idList.AddRange(ltf.Items);
     *               }
     *           }
     *           using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               BinaryWriter sw = new BinaryWriter(fs);
     *               for (int i = 0; i < idList.Count; i++)
     *               {
     *                   sw.Write(idList[i]);
     *               }
     *               sw.Close();
     *           }
     *       }
     *   }
     * }
     *
     * /// <summary>
     * /// 在线写入日志数据(id和帧数)
     * /// </summary>
     * /// <param name="path">文件写入的路径</param>
     * /// <param name="cq">保存近60帧数据的循环队列</param>
     * public void WriteLogIDAndFrameIndex(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq != null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       if (cqLength != 0)
     *       {
     *           cq.ResetCur();
     *           List<int> idAndFrameList = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   //按照FrameIndex-Id序列-最大值格式存储
     *                   idAndFrameList.Add(ltf.FrameIndex);
     *                   idAndFrameList.AddRange(ltf.Items);
     *                   idAndFrameList.Add(int.MaxValue);
     *               }
     *           }
     *           using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *           {
     *               BinaryWriter sw = new BinaryWriter(fs);
     *               for (int i = 0; i < idAndFrameList.Count; i++)
     *               {
     *                   sw.Write(idAndFrameList[i]);
     *               }
     *               sw.Close();
     *           }
     *       }
     *   }
     * }
     *
     * /// <summary>
     * /// 在线写入日志数据(id和帧数、参数)
     * /// </summary>
     * /// <param name="path"></param>
     * /// <param name="cq"></param>
     * public void WriteLogIDAndFrameIndexAndArgs(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *   if (cq!=null)
     *   {
     *       int cqLength = cq.QueueLength();
     *       cq.ResetCur();
     *       if (cqLength!=0)
     *       {
     *           List<int> idAndFrameWithArgs = new List<int>();
     *           for (int i = 0; i < cqLength; i++)
     *           {
     *               LogTrackFrame ltf = cq.GetNext();
     *               if (ltf != null)
     *               {
     *                   //按照(帧-ID序列-最小值-Args序列-最大值)格式存储
     *                   idAndFrameWithArgs.Add(ltf.FrameIndex);
     *                   idAndFrameWithArgs.AddRange(ltf.Items);
     *                   idAndFrameWithArgs.Add(int.MinValue);
     *                   idAndFrameWithArgs.AddRange(ltf.Args);
     *                   Debug.Log("---------------------");
     *                   Debug.Log(ltf.Args.Count);
     *                   idAndFrameWithArgs.Add(int.MaxValue);
     *               }
     *           }
     *           if (idAndFrameWithArgs.Count!=0)
     *           {
     *               using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *               {
     *                   BinaryWriter sw = new BinaryWriter(fs);
     *                   for (int i = 0; i < idAndFrameWithArgs.Count; i++)
     *                   {
     *                       sw.Write(idAndFrameWithArgs[i]);
     *                   }
     *                   sw.Close();
     *               }
     *           }
     *       }
     *   }
     * }
     *
     *
     * /// <summary>
     * /// 日志数据反解(id和Args)
     * /// </summary>
     * /// <param name="inputLogDataPath">二进制日志数据输入路径</param>
     * /// <param name="outputLogDataPath">可读性的日志数据路径输出路径</param>
     * public void LogDataInverseIdWithArgs(string inputLogDataPath, string outputLogDataPath,string LogPdbPath)
     * {
     *
     *   if (!File.Exists(inputLogDataPath))
     *   {
     *       return;
     *   }
     *   //读取的日志数据
     *   string strMsg;
     *   List<int> idAry = new List<int>();
     *   List<int> argAry = new List<int>();
     *   //读取二进制日志数据
     *   using (FileStream fs = new FileStream(inputLogDataPath, FileMode.Open, FileAccess.Read))
     *   {
     *       BinaryReader br = new BinaryReader(fs);
     *       while (br.PeekChar() > -1)
     *       {
     *           idAry.Add(br.ReadInt32());
     *       }
     *       br.Close();
     *   }
     *   if (idAry.Count!=0)
     *   {
     *       int i = idAry.Count - 1;
     *       for (; idAry[i]!= int.MaxValue; i--)
     *       {
     *           argAry.Add(idAry[i]);
     *       }
     *       idAry.RemoveRange(i, idAry.Count-i);
     *       argAry.Reverse();
     *   }
     *   strMsg= JsonHandler.OutputAllMes(idAry, argAry, LogPdbPath);
     *   if (strMsg!=null)
     *   {
     *       //写数据
     *       using (FileStream fs = new FileStream(outputLogDataPath, FileMode.OpenOrCreate, FileAccess.Write))
     *       {
     *           byte[] by= Encoding.UTF8.GetBytes(strMsg);
     *           fs.Write(by, 0, by.Length);
     *       }
     *   }
     *
     * }
     *
     *
     * /// <summary>
     * /// 日志数据反解(id)
     * /// </summary>
     * /// <param name="inputLogDataPath">二进制日志数据输入路径</param>
     * /// <param name="outputLogDataPath">可读性的日志数据路径输出路径</param>
     * public void LogDataInverseId(string inputLogDataPath,string outputLogDataPath,string logPdbFilepath)
     * {
     *
     *   if (!File.Exists(inputLogDataPath))
     *   {
     *       return;
     *   }
     *   //读取的日志数据
     *   string strMsg;
     *   List<int> idAry = new List<int>();
     *   //读取二进制日志数据
     *   using (FileStream fs = new FileStream(inputLogDataPath, FileMode.Open, FileAccess.Read))
     *   {
     *       BinaryReader br = new BinaryReader(fs);
     *       while (br.PeekChar() > -1)
     *       {
     *           idAry.Add(br.ReadInt32());
     *       }
     *       br.Close();
     *   }
     *   strMsg = JsonHandler.OutputAllMes(idAry,logPdbFilepath);
     *   if (strMsg != null)
     *   {
     *       //写数据
     *       using (FileStream fs = new FileStream(outputLogDataPath, FileMode.OpenOrCreate, FileAccess.Write))
     *       {
     *           byte[] by = Encoding.UTF8.GetBytes(strMsg);
     *           fs.Write(by, 0, by.Length);
     *       }
     *   }
     *
     * }
     *
     * /// <summary>
     * /// 日志数据反解(id和帧数)
     * /// </summary>
     * /// <param name="inputLogDataPath">二进制数据路径</param>
     * /// <param name="outputLogDataPath">输出可读性日志路径</param>
     * /// <param name="logPdbFilepath">LogPdb映射表的路径</param>
     * public void LogDataInverseIDAndFrameIndex(string inputLogDataPath, string outputLogDataPath, string logPdbFilepath)
     * {
     *   if (!File.Exists(inputLogDataPath))
     *   {
     *       return;
     *   }
     *   //读取的日志数据
     *   string strMsg;
     *   //用于存储帧索引-函数ID序列
     *   Dictionary<int, List<int>> frameIdDic = new Dictionary<int, List<int>>();
     *   //存储读取的所有数据
     *   List<int> binData = new List<int>();
     *   //读取二进制日志数据
     *   using (FileStream fs = new FileStream(inputLogDataPath, FileMode.Open, FileAccess.Read))
     *   {
     *       BinaryReader br = new BinaryReader(fs);
     *       while (br.PeekChar() > -1)
     *       {
     *           binData.Add(br.ReadInt32());
     *       }
     *       br.Close();
     *   }
     *   int curIndex = 0;
     *   int binDataCnt = binData.Count;
     *   //对读取的集合进行分割处理
     *   while (curIndex<binDataCnt)
     *   {
     *       List<int> idAndFrameAry = new List<int>();
     *       for (;binData[curIndex] !=int.MaxValue ; curIndex++)
     *       {
     *           idAndFrameAry.Add(binData[curIndex]);
     *       }
     *       //跳过最大值(用最大值来分隔每帧的函数调用序列)
     *       curIndex++;
     *       //将数据保存至字典中(列表中第一个数是帧索引,后面则是函数ID序列)
     *       int frameIndex = idAndFrameAry[0];
     *       idAndFrameAry.RemoveAt(0);
     *       frameIdDic.Add(frameIndex, idAndFrameAry);
     *   }
     *   strMsg = JsonHandler.OutputAllMes(frameIdDic, logPdbFilepath);
     *   if (strMsg != null)
     *   {
     *       //写数据
     *       using (FileStream fs = new FileStream(outputLogDataPath, FileMode.OpenOrCreate, FileAccess.Write))
     *       {
     *           byte[] by = Encoding.UTF8.GetBytes(strMsg);
     *           fs.Write(by, 0, by.Length);
     *       }
     *   }
     *
     * }
     *
     * /// <summary>
     * /// 日志数据反解(id和帧数、参数)
     * /// </summary>
     * /// <param name="inputLogDataPath"></param>
     * /// <param name="outputLogDataPath"></param>
     * /// <param name="logPdbFilepath"></param>
     * public void LogDataInverseIDAndFrameIndexWithArgs(string inputLogDataPath, string outputLogDataPath, string logPdbFilepath)
     * {
     *   if (!File.Exists(inputLogDataPath))
     *   {
     *       return;
     *   }
     *   //读取的日志数据
     *   string strMsg;
     *   //用于存储帧索引-函数ID序列
     *   Dictionary<int, List<int>> frameIdDic = new Dictionary<int, List<int>>();
     *   //存储读取的所有数据
     *   List<int> binData = new List<int>();
     *   //存储所有参数
     *   List<int> argsList = new List<int>();
     *   //读取二进制日志数据
     *   using (FileStream fs = new FileStream(inputLogDataPath, FileMode.Open, FileAccess.Read))
     *   {
     *       BinaryReader br = new BinaryReader(fs);
     *       while (br.PeekChar() > -1)
     *       {
     *           binData.Add(br.ReadInt32());
     *       }
     *       br.Close();
     *   }
     *   //记录遍历的位置
     *   int curIndex = 0;
     *   int binDataCnt = binData.Count;
     *   //对读取的集合进行分割处理
     *   while (curIndex < binDataCnt)
     *   {
     *       List<int> idAndFrameAryWithArgs = new List<int>();
     *       for (; binData[curIndex] != int.MaxValue; curIndex++)
     *       {
     *           idAndFrameAryWithArgs.Add(binData[curIndex]);
     *       }
     *       //跳过最大值(用最大值来分隔每帧的函数调用序列)
     *       curIndex++;
     *       //列表中第一个数是帧索引,后面则是函数ID序列和参数序列
     *       int frameIndex = idAndFrameAryWithArgs[0];
     *       //移除帧索引
     *       idAndFrameAryWithArgs.RemoveAt(0);
     *       //分隔Id序列和Args序列(最小值分隔)
     *       //用于记录遍历的位置
     *       int i = idAndFrameAryWithArgs.Count-1;
     *       //存储每帧的参数序列
     *       List<int> tempArgsList = new List<int>();
     *       while (idAndFrameAryWithArgs[i]!=int.MinValue)
     *       {
     *           tempArgsList.Add(idAndFrameAryWithArgs[i]);
     *           i--;
     *       }
     *       //移除Args序列
     *       idAndFrameAryWithArgs.RemoveRange(i, idAndFrameAryWithArgs.Count - i);
     *       //需要反转一下
     *       tempArgsList.Reverse();
     *       //存储至Args集合中
     *       argsList.AddRange(tempArgsList);
     *       frameIdDic.Add(frameIndex, idAndFrameAryWithArgs);
     *   }
     *   strMsg = JsonHandler.OutputAllMes(frameIdDic, argsList,logPdbFilepath);
     *   if (strMsg != null)
     *   {
     *       //写数据
     *       using (FileStream fs = new FileStream(outputLogDataPath, FileMode.OpenOrCreate, FileAccess.Write))
     *       {
     *           byte[] by = Encoding.UTF8.GetBytes(strMsg);
     *           fs.Write(by, 0, by.Length);
     *       }
     *   }
     * }
     */
    /*
     * /// <summary>
     * /// 序列化数据
     * /// </summary>
     * /// <param name="cq"></param>
     * /// <param name="path"></param>
     * public void LogDataSerlializer(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *  if (cq!=null)
     *  {
     *      int length = cq.QueueLength();
     *      if (length!=0)
     *      {
     *          cq.ResetCur();
     *          List<LogTrackFrame> ltfList = new List<LogTrackFrame>();
     *          for (int i = 0; i < length; i++)
     *          {
     *              ltfList.Add(cq.GetNext());
     *          }
     *          using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
     *          {
     *              ProtoBuf.Serializer.Serialize<List<LogTrackFrame>>(fs, ltfList);
     *          }
     *      }
     *  }
     * }
     *
     * /// <summary>
     * /// 序列化后进行Gzip压缩
     * /// </summary>
     * /// <param name="path"></param>
     * /// <param name="cq"></param>
     * public void LogDataSerlializerAndCompress(string path, CircleQueue<LogTrackFrame> cq)
     * {
     *  if (cq != null)
     *  {
     *      int length = cq.QueueLength();
     *      if (length != 0)
     *      {
     *          cq.ResetCur();
     *          List<LogTrackFrame> ltfList = new List<LogTrackFrame>();
     *          for (int i = 0; i < length; i++)
     *          {
     *              ltfList.Add(cq.GetNext());
     *          }
     *          using (MemoryStream ms=new MemoryStream())
     *          {
     *              using (var gzipStream =new GZipOutputStream(File.Open(path,FileMode.Create)))
     *              {
     *                  //将数据序列化后写至内存流中
     *                  ProtoBuf.Serializer.Serialize<List<LogTrackFrame>>(ms, ltfList);
     *                  // 重置内存流的读写位置(此步很关键)
     *                  ms.Position = 0;
     *                  //定义缓冲区大小
     *                  int buffersize = 1024;
     *                  //创建缓冲数据
     *                  byte[] FileData = new byte[buffersize];
     *                  //循环读写
     *                  while (buffersize > 0)
     *                  {
     *                      //先将内存流中的数据读到缓冲区中
     *                      buffersize = ms.Read(FileData, 0, buffersize);
     *                      //把缓冲区中数据写入到文件流中
     *                      gzipStream.Write(FileData, 0, buffersize);//写入压缩文件
     *                  }
     *              }
     *          }
     *
     *      }
     *  }
     * }
     *
     * /// <summary>
     * /// 解压并进行反序列化
     * /// </summary>
     * /// <param name="path"></param>
     * /// <param name="pdbFilePath"></param>
     * /// <param name="outputLogDataPath"></param>
     * public void ReLogDataSerlializerAndUncompress(string path, string pdbFilePath, string outputLogDataPath)
     * {
     *  if (!File.Exists(path))
     *  {
     *      return;
     *  }
     *  List<LogTrackFrame> ltfList = new List<LogTrackFrame>();
     *  using (MemoryStream ms = new MemoryStream())
     *  {
     *      //解压
     *      using (var stream = new GZipInputStream(File.OpenRead(path)))
     *      {
     *          int buffersize = 2048;
     *          byte[] buffer = new byte[buffersize];
     *          while (buffersize > 0)
     *          {
     *              buffersize = stream.Read(buffer, 0, buffersize);
     *              ms.Write(buffer, 0, buffersize);
     *          }
     *      }
     *      ms.Position = 0;
     *      //反序列化
     *      ltfList = ProtoBuf.Serializer.Deserialize<List<LogTrackFrame>>(ms);
     *  }
     *  LogDataInverse(ltfList, pdbFilePath, outputLogDataPath);
     * }
     *
     * /// <summary>
     * /// 反序列化数据
     * /// </summary>
     * /// <param name="path">二进制文件路径</param>
     * /// <param name="pdbFilePath">Pdb表路径</param>
     * /// <param name="outputLogDataPath">输出路径</param>
     * public void ReLogDataSerlializer(string path,string pdbFilePath, string outputLogDataPath)
     * {
     *  if (!File.Exists(path))
     *  {
     *      return;
     *  }
     *  List<LogTrackFrame> ltfList = new List<LogTrackFrame>();
     *  using (FileStream fs=new FileStream(path,FileMode.Open,FileAccess.Read))
     *  {
     *      ltfList=  ProtoBuf.Serializer.Deserialize<List<LogTrackFrame>>(fs);
     *  }
     *  Debug.Log("Ok");
     *  LogDataInverse(ltfList, pdbFilePath, outputLogDataPath);
     * }
     *
     * /// <summary>
     * /// 反序列化数据反解
     * /// </summary>
     * /// <param name="ltfList"></param>
     * /// <param name="logpdbFilePath"></param>
     * /// <param name="outputLogDataPath"></param>
     * public void LogDataInverse(List<LogTrackFrame> list,string logpdbFilePath,string outputLogDataPath)
     * {
     *  if (list != null&& list.Count!=0)
     *  {
     *      //读取的日志数据
     *      string strMsg;
     *      int cnt = list.Count;
     *      //用于存储帧索引-函数ID序列
     *      Dictionary<int, List<ushort>> frameIdDic = new Dictionary<int, List<ushort>>();
     *      //存储所有参数
     *      List<int> argsList = new List<int>();
     *      for (int i = 0; i < cnt; i++)
     *      {
     *          int frameIndex = list[i].FrameIndex;
     *          List<ushort> idList = new List<ushort>();
     *          idList.AddRange(list[i].Items);
     *          if (list[i].Args!=null&&list[i].Args.Count!=0)
     *          {
     *              argsList.AddRange(list[i].Args);
     *          }
     *          frameIdDic.Add(frameIndex, idList);
     *      }
     *      strMsg = JsonHandler.OutputAllMes(frameIdDic, argsList, logpdbFilePath);
     *      if (strMsg != null)
     *      {
     *          //写数据
     *          using (FileStream fs = new FileStream(outputLogDataPath, FileMode.OpenOrCreate, FileAccess.Write))
     *          {
     *              byte[] by = Encoding.UTF8.GetBytes(strMsg);
     *              fs.Write(by, 0, by.Length);
     *          }
     *      }
     *  }
     * }
     */
    /// <summary>
    /// 序列化数据
    /// </summary>
    /// <param name="cq"></param>
    /// <param name="path"></param>
    public void LogDataSerlializer(string path, CircleQueue <LogTrackFunc> cq)
    {
        if (cq != null)
        {
            int length = cq.QueueLength();
            if (length != 0)
            {
                //cq.ResetCur();

                /*
                 * List<LogTrackFunc> ltfList = new List<LogTrackFunc>();
                 * for (int i = 0; i < length; i++)
                 * {
                 *  ltfList.Add(cq.GetNext());
                 * }
                 */
                using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    // ProtoBuf.Serializer.Serialize<List<LogTrackFunc>>(fs, ltfList);
                    ProtoBuf.Serializer.Serialize <CircleQueue <LogTrackFunc> >(fs, cq);
                }
            }
        }
    }
Beispiel #13
0
 public ProtocolItem()
 {
     m_Queue  = null;
     m_bUsing = false;
     m_Queue  = new CircleQueue();
 }
Beispiel #14
0
 public void method_0(int int_0, CbGeneric <T> pointer)
 {
     this.circleQueue_0 = new CircleQueue <T>(int_0);
     this.cbGeneric_0   = pointer;
 }
Beispiel #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="a_cq"></param>
 public BeachLine(CircleQueue a_cq)
 {
     circleQueue  = a_cq;
     recycledArcs = new Stack <Arc>();
 }
        public void NewQueueIsEmpty()
        {
            var queue = new CircleQueue <double>();

            Assert.IsTrue(queue.IsEmpty);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine(ReverseWords.MyReverseWords("a good   example"));
            Console.ReadLine();
            #region 雪花算法生成ID
            // SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator();

            #endregion

            SingleLinkedList <int> list = new SingleLinkedList <int>();
            for (int i = 0; i < 4; i++)
            {
                list.InsertToTail(i + 1);
            }
            list.Reverse(list.Head);
            Array_Test();

            Merge_LinkedList_Test();
            var q = new Person {
                Id = 1, Name = "marson"
            };
            var p = q;
            q = new Person {
                Id = 2, Name = "shine"
            };
            Console.WriteLine(ReferenceEquals(p, q));
            Console.WriteLine(q == p);
            Console.WriteLine("q.hashCode=" + q.GetHashCode() + " p.hashCode=" + p.GetHashCode());

            var    a   = new ThreeSum(new int[] { 0, 1, 2, -1, -4 }).Sum(new int[] { 0, 1, 2, -1, -4 });
            string str = "[";
            foreach (var b in a)
            {
                str += "[";
                foreach (var c in b)
                {
                    str += c + ",";
                }
                str += "],";
            }
            str += "]";
            Console.WriteLine(str);

            // new TwoSum()._TwoSum(new [] { 2, 7, 11, 15 }, 9);
            new TwoSum().__TwoSum(new [] { 3, 2, 4 }, 6);
            new _MajorityElement().MajorityElement(new [] { 2, 2, 1, 1, 1, 2, 2 });
            Console.WriteLine(new _FirstMissingPositive().FirstMissingPositive(new [] { 1, 2, 0 }));

            var nodes = new SingleLinkedList <int>();
            var n     = new SingleLinkedListNode <int>(0);
            nodes.InsertToHead(new SingleLinkedListNode <int>(3));
            nodes.InsertToTail(new SingleLinkedListNode <int>(2));
            nodes.InsertToTail(n);
            nodes.InsertToTail(new SingleLinkedListNode <int>(-4));
            // var n = new SingleLinkedListNode<int>(1);
            nodes.HasCycle(nodes.Head);

            var sequenceStack = new SequenceStack <string>(15);
            for (int i = 0; i < 25; i++)
            {
                sequenceStack.Push("数据内容" + (i + 1));
            }
            int count = sequenceStack.Length;
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(sequenceStack.Pop());
            }

            var linkedStack = new LinkedStack <string>(15);
            for (int i = 0; i < 15; i++)
            {
                linkedStack.Push("数据内容" + (i + 1));
            }

            var linkedQueue = new LinkedQueue <string>(5);
            for (int i = 0; i < 5; i++)
            {
                linkedQueue.Enqueue("数据内容" + i);
                Console.WriteLine($"数据容量 capacity={linkedQueue.Capacity} 数据个数 length={linkedQueue.Length}");
            }
            for (int i = 0; i < 5; i++)
            {
                linkedQueue.Dequeue();
                Console.WriteLine($"数据容量 capacity={linkedQueue.Capacity} 数据个数 length={linkedQueue.Length}");
            }
            var circle = new CircleQueue <string>(5);
            for (int i = 0; i < 5; i++)
            {
                circle.Enqueue("数据内容" + i);
                Console.WriteLine($"数据容量 capacity={circle.Capacity} 数据个数 length={circle.Length}");
            }
            for (int i = 0; i < 5; i++)
            {
                var c = circle.Dequeue();
                Console.WriteLine($"数据容量 capacity={circle.Capacity} 数据个数 length={circle.Length}");
            }

            Demonstrations demonstrations = new Demonstrations();
            Console.WriteLine(demonstrations.FibRecursionTail(8, 0, 1));
            Console.WriteLine(demonstrations.Factorial(8) + " 递归:" + demonstrations.FactorialRecursion(8) + " 尾递归:" + demonstrations.FactorialRecursionTail(8, 1));

            BigSort <int> sort   = new BigSort <int>();
            var           source = new [] { 1, 2, 3, 6, 2, 4, 8, 0, 11, 2, 3, 6, 3, 1 };
            sort.MergeSort(source);
            Console.WriteLine(source);
            var sources = new [] { 4, 5, 6, 1, 2, 3 };
            // sort.BublleSort(sources);
            // sort.BublleSortOptimize(sources);
            // sort.InsertionSort(sources);
            sort.SelectionSort(new [] { 1, 2, 3, 7, 1, 2, 3, 5, 6, 7, 10, 9, 6, 5, 4, 2 });

            var sqrt   = new SqrtX();
            int sqrted = int.MaxValue;
            Console.WriteLine($"{sqrted} 的平方根整数值为:{sqrt.Sqrt(sqrted)}");

            LRUBaseLinkedHashTable <int, string> hashtables = new LRUBaseLinkedHashTable <int, string>(5);
            //insert
            for (int i = 0; i < hashtables.Capacity; i++)
            {
                hashtables.Add(i, "marson" + i);
            }
            //print
            hashtables.Print();
            Console.WriteLine();
            //random visitor
            var random = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < hashtables.Capacity; i++)
            {
                var r = random.Next(0, 3);
                var v = hashtables.GetValue(r);
                Console.WriteLine($"visit key:{v}");
                hashtables.Print();
            }

            ReverseString rs = new ReverseString();
            var           s  = new [] { '\'', '\\', '{' };
            rs.Reverse(s);
            Console.WriteLine("Reverse:" + string.Join(' ', s));

            BinaryTree <int> bt = new BinaryTree <int>();
            bt.Insert(16);
            bt.Insert(14);
            bt.Insert(20);
            bt.Insert(18);
            bt.Insert(19);
            bt.Insert(23);
            Console.WriteLine("找到的值:" + bt.Find(19).Value);
            bt.Delete(20);
            Console.WriteLine("删除含有两个子节点的节点");

            HeadSort <int> hs = new HeadSort <int>();
            Random         rd = new Random((int)DateTime.Now.Ticks);
            for (int i = 0; i < 10; i++)
            {
                hs.Insert(rd.Next(100));
            }
        }