Esempio n. 1
0
        public void GetSourceTest()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                Console.WriteLine("Testing GetSource function with {0} Iterations.", Iterations);

                ulong counter = 0;

                //var firstLink = links.First();
                // Создаём одну связь, из которой будет производить считывание
                ulong firstLink = links.Create(0, 0);

                Stopwatch sw = Stopwatch.StartNew();

                // Тестируем саму функцию
                for (ulong i = 0; i < Iterations; i++)
                    counter += links.GetSource(firstLink);

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds;

                // Удаляем связь, из которой производилось считывание
                links.Delete(firstLink);

                Console.WriteLine(
                    "{0} Iterations of GetSource function done in {1} ({2} Iterations per second), counter result: {3}",
                    Iterations, elapsedTime, (long)iterationsPerSecond, counter);
            }

            File.Delete(tempFilename);
        }
        public void PatternMatchTest()
        {
            string tempFilename = Path.GetTempFileName();

            const ulong itself = Links.Itself;
            const ulong one = Sequences.Any;
            const ulong zeroOrMany = Sequences.ZeroOrMany;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var e1 = links.Create(itself, itself);
                var e2 = links.Create(itself, itself);

                var sequence = new[]
                {
                    e1, e2, e1, e2 // mama / papa
                };

                var sequences = new Sequences(links);

                var balancedVariant = sequences.CreateBalancedVariant(sequence);

                // 1: [1]
                // 2: [2]
                // 3: [1,2]
                // 4: [1,2,1,2]

                var pair = links.GetSource(balancedVariant);

                var matchedSequences1 = sequences.MatchPattern(e2, e1, zeroOrMany);

                Assert.IsTrue(matchedSequences1.Count == 0);

                var matchedSequences2 = sequences.MatchPattern(zeroOrMany, e2, e1);

                Assert.IsTrue(matchedSequences2.Count == 0);

                var matchedSequences3 = sequences.MatchPattern(e1, zeroOrMany, e1);

                Assert.IsTrue(matchedSequences3.Count == 0);

                var matchedSequences4 = sequences.MatchPattern(e1, zeroOrMany, e2);

                Assert.IsTrue(matchedSequences4.Contains(pair));
                Assert.IsTrue(matchedSequences4.Contains(balancedVariant));

                for (int i = 0; i < sequence.Length; i++)
                    links.Delete(sequence[i]);
            }

            File.Delete(tempFilename);
        }
Esempio n. 3
0
        public void GetSourceInParallel()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                Console.WriteLine("Testing GetSource function with {0} Iterations in parallel.", Iterations);

                long counter = 0;

                //var firstLink = links.First();
                ulong firstLink = links.Create(0, 0);

                Stopwatch sw = Stopwatch.StartNew();

                // Тестируем саму функцию
                Parallel.For(0, Iterations, x =>
                {
                    Interlocked.Add(ref counter, (long)links.GetSource(firstLink));
                    //Interlocked.Increment(ref counter);
                });

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds;

                links.Delete(firstLink);

                Console.WriteLine(
                    "{0} Iterations of GetSource function done in {1} ({2} Iterations per second), counter result: {3}",
                    Iterations, elapsedTime, (long)iterationsPerSecond, counter);
            }

            File.Delete(tempFilename);
        }
Esempio n. 4
0
        private static void PrintContents(Links links, Sequences sequences)
        {
            if (links.Total == UTF16LastCharLink)
                Console.WriteLine("Database is empty.");
            else
            {
                Console.WriteLine("Contents:");

                var linksTotalLength = links.Total.ToString("0").Length;

                var printFormatBase = new String('0', linksTotalLength);

                // Выделить код по печати одной связи в Extensions

                var printFormat = string.Format("\t[{{0:{0}}}]: {{1:{0}}} -> {{2:{0}}} {{3}}", printFormatBase);

                for (var link = UTF16LastCharLink + 1; link <= links.Total; link++)
                {
                    Console.WriteLine(printFormat, link, links.GetSource(link), links.GetTarget(link),
                        sequences.FormatSequence(link, AppendLinkToString, true));
                }
            }
        }