コード例 #1
0
        public void TestMerge()
        {
            var first  = new Interval(5, 1);
            var second = new Interval(9, 3);
            var third  = new Interval(12, 7);
            var merged = Intervals.Merge(new Interval[] { second, third, first });

            Assert.AreEqual(1, merged.Count);
            Assert.AreEqual(first.a, merged[0].a);
            Assert.AreEqual(third.b, merged[0].b);
        }
コード例 #2
0
        public void TestMergeIntervals()
        {
            var v5 = new Interval(1, 3);
            var v1 = new Interval(2, 6);
            var v3 = new Interval(5, 10);
            var v4 = new Interval(15, 21);
            var v2 = new Interval(18, 19);
            var v6 = new Interval(22, 23);
            var vs = new[] { v1, v2, v3, v4, v5, v6 };

            var r = Intervals.Merge(vs);

            Assert.AreEqual(r.Count, 3);
            Assert.AreEqual(r[0].Start, 1);
            Assert.AreEqual(r[1].End, 21);
        }
コード例 #3
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
        // clears unused log lines to free some memory before chunks parsing
        private void OptimizeLogMemory()
        {
            Stopwatch sw = Stopwatch.StartNew();

            var intervals = Chunks.Select(c => new Interval(c.Header.Index, c.Footer.Index));
            var merged    = Intervals.Merge(intervals);
            int counter   = 0;

            // trim middles
            for (int i = 0; i < merged.Count - 1; i++)
            {
                for (int idx = merged[i].b; idx <= merged[i + 1].a; idx++)
                {
                    Log.FreeLine(i);
                    counter++;
                }
            }

            Trace.WriteLine(string.Format("{0} lines freed in {1}.", counter, sw.Elapsed));
            GC.Collect();
        }