Exemplo n.º 1
0
        private static void InitUTF16(Links links)
        {
            if (UTF16Initialized)
                return;

            UTF16Initialized = true;
            UTF16FirstCharLink = 1;
            UTF16LastCharLink = UTF16FirstCharLink + char.MaxValue;

            var firstLink = links.Create(0, 0);

            if (firstLink != UTF16FirstCharLink)
            {
                links.Delete(firstLink);
                Console.WriteLine("Assume UTF16 table already created.");
            }
            else
            {
                for (var i = UTF16FirstCharLink + 1; i <= UTF16LastCharLink; i++)
                {
                    // From NIL to It (NIL -> Character) transformation meaning, (or infinite amount of NIL characters before actual Character)
                    var createdLink = links.Create(firstLink, 0);
                    if (createdLink != i)
                        throw new Exception("Unable to initialize UTF 16 table.");
                }

                Console.WriteLine("UTF16 table created and initialized.");
            }

            Console.WriteLine("Total links count: {0}.", links.Total);
        }
Exemplo n.º 2
0
        public void AllPartialVariantsSearchTest()
        {
            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 8;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var createResults = sequences.CreateAllVariants2(sequence);

                //var createResultsStrings = createResults.Select(x => x + ": " + sequences.FormatSequence(x)).ToList();
                //Global.Trash = createResultsStrings;

                var partialSequence = new ulong[sequenceLength - 2];

                Array.Copy(sequence, 1, partialSequence, 0, sequenceLength - 2);

                var sw1 = Stopwatch.StartNew();
                var searchResults1 = sequences.GetAllPartiallyMatchingSequences0(partialSequence); sw1.Stop();

                var sw2 = Stopwatch.StartNew();
                var searchResults2 = sequences.GetAllPartiallyMatchingSequences1(partialSequence); sw2.Stop();

                //var sw3 = Stopwatch.StartNew();
                //var searchResults3 = sequences.GetAllPartiallyMatchingSequences2(partialSequence); sw3.Stop();

                //Global.Trash = searchResults3;

                //var searchResults1Strings = searchResults1.Select(x => x + ": " + sequences.FormatSequence(x)).ToList();
                //Global.Trash = searchResults1Strings;

                var intersection1 = createResults.Intersect(searchResults1).ToList();
                Assert.IsTrue(intersection1.Count == createResults.Length);

                var intersection2 = createResults.Intersect(searchResults2).ToList();
                Assert.IsTrue(intersection2.Count == createResults.Length);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 3
0
 public AllUsagesIntersectingCollector(Links links, HashSet<ulong> intersectWith, HashSet<ulong> usages)
 {
     _links = links;
     _intersectWith = intersectWith;
     _usages = usages;
     _enter = new HashSet<ulong>(); // защита от зацикливания
 }
 public LinksTargetsTreeMethods(Links links, LinksHeader* header)
 {
     _db = links;
     _links = links._links;
     _header = header;
 }
Exemplo n.º 5
0
        public void TransactionsTest()
        {
            var tempDatabaseFilename = Path.GetTempFileName();
            var tempTransactionLogFilename = Path.GetTempFileName();

            const ulong itself = Links.Itself;

            // Auto Reverted (Because no commit at transaction)
            using (var links = new Links(tempDatabaseFilename,
                    tempTransactionLogFilename, 1024 * 1024))
            {
                using (var transaction = links.BeginTransaction())
                {
                    var l1 = links.Create(itself, itself);
                    var l2 = links.Create(itself, itself);

                    Global.Trash = links.Update(l2, l2, l1, l2);

                    links.Delete(l1);

                    Global.Trash = transaction;
                }

                Global.Trash = links.Total;
            }

            Global.Trash = FileHelpers
                .ReadAll<Links.Transition>(tempTransactionLogFilename);

            // User Code Error (Autoreverted)
            try
            {
                using (var links = new Links(tempDatabaseFilename,
                    tempTransactionLogFilename, 1024 * 1024))
                {
                    using (var transaction = links.BeginTransaction())
                    {
                        var l1 = links.Create(itself, itself);
                        var l2 = links.Create(itself, itself);

                        l2 = links.Update(l2, l2, l1, l2);

                        links.Create(l2, itself);
                        links.Create(l2, itself);

                        ExceptionThrower();

                        l2 = links.Update(l2, l1); // TODO: Fix CascadeUpdateTest and move ExceptionThrower() before transaction.Commit()

                        links.Delete(l2);

                        transaction.Commit();
                    }

                    Global.Trash = links.Total;
                }
            }
            catch
            {
                Global.Trash = FileHelpers
                    .ReadAll<Links.Transition>(tempTransactionLogFilename);
            }

            // Commit
            using (var links = new Links(tempDatabaseFilename,
                    tempTransactionLogFilename, 1024 * 1024))
            {
                using (var transaction = links.BeginTransaction())
                {
                    var l1 = links.Create(itself, itself);
                    var l2 = links.Create(itself, itself);

                    Global.Trash = links.Update(l2, l2, l1, l2);

                    links.Delete(l1);

                    transaction.Commit();
                }

                Global.Trash = links.Total;
            }

            Global.Trash = FileHelpers
                .ReadAll<Links.Transition>(tempTransactionLogFilename);

            // Damage database

            FileHelpers
                .WriteFirst(tempTransactionLogFilename, new Links.Transition { TransactionId = 555 });

            // Try load damaged database
            try
            {
                // TODO: Fix
                using (var links = new Links(tempDatabaseFilename,
                        tempTransactionLogFilename, 1024 * 1024))
                {
                    Global.Trash = links.Total;
                }
            }
            catch (NotSupportedException ex)
            {
                Assert.IsTrue(ex.Message == "Database is damaged, autorecovery is not supported yet.");
            }

            Global.Trash = FileHelpers
                .ReadAll<Links.Transition>(tempTransactionLogFilename);

            File.Delete(tempDatabaseFilename);
            File.Delete(tempTransactionLogFilename);
        }
Exemplo n.º 6
0
        public void TestGetTargetInParallel()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                Console.WriteLine("Testing GetTarget 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.GetTarget(firstLink));
                    //Interlocked.Increment(ref counter);
                });

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds;

                links.Delete(firstLink);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 7
0
        public void TestEach()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong counter = 0;

                Console.WriteLine("Testing Each function.");

                Stopwatch sw = Stopwatch.StartNew();

                links.Each(0, 0, x =>
                {
                    counter++;

                    return true;
                });

                TimeSpan elapsedTime = sw.Elapsed;

                double linksPerSecond = counter / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} Iterations of Each's handler function done in {1} ({2} links per second)",
                    counter, elapsedTime, (long)linksPerSecond);
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void BasicTransactionLogTest()
        {
            var tempDatabaseFilename = Path.GetTempFileName();
            var tempTransactionLogFilename = Path.GetTempFileName();

            const ulong itself = Links.Itself;

            using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024))
            {
                var l1 = links.Create(itself, itself);
                var l2 = links.Create(itself, itself);

                Global.Trash = links.Update(l2, l2, l1, l2);

                links.Delete(l1);
            }

            Global.Trash = FileHelpers
                .ReadAll<Links.Transition>(tempTransactionLogFilename);

            File.Delete(tempDatabaseFilename);
            File.Delete(tempTransactionLogFilename);
        }
Exemplo n.º 10
0
        public void BalancedPartialVariantsSearchTest()
        {
            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 200;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var balancedVariant = sequences.CreateBalancedVariant(sequence);

                var partialSequence = new ulong[sequenceLength - 2];

                Array.Copy(sequence, 1, partialSequence, 0, sequenceLength - 2);

                var sw1 = Stopwatch.StartNew();
                var searchResults1 = sequences.GetAllPartiallyMatchingSequences0(partialSequence); sw1.Stop();

                var sw2 = Stopwatch.StartNew();
                var searchResults2 = sequences.GetAllPartiallyMatchingSequences1(partialSequence); sw2.Stop();

                Assert.IsTrue(searchResults1.Count == 1 && balancedVariant == searchResults1[0]);

                Assert.IsTrue(searchResults2.Count == 1 && balancedVariant == searchResults2.First());

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

            File.Delete(tempFilename);
        }
Exemplo n.º 11
0
        public void AllVariantsSearchTest()
        {
            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 8;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var createResults = sequences.CreateAllVariants2(sequence).Distinct().ToArray();

                var sw0 = Stopwatch.StartNew();
                var searchResults0 = sequences.GetAllMatchingSequences0(sequence); sw0.Stop();

                var sw1 = Stopwatch.StartNew();
                var searchResults1 = sequences.GetAllMatchingSequences1(sequence); sw1.Stop();

                var sw2 = Stopwatch.StartNew();
                var searchResults2 = sequences.Each(sequence); sw2.Stop();

                var intersection0 = createResults.Intersect(searchResults0).ToList();
                Assert.IsTrue(intersection0.Count == searchResults0.Count);
                Assert.IsTrue(intersection0.Count == createResults.Length);

                var intersection1 = createResults.Intersect(searchResults1).ToList();
                Assert.IsTrue(intersection1.Count == searchResults1.Count);
                Assert.IsTrue(intersection1.Count == createResults.Length);

                var intersection2 = createResults.Intersect(searchResults2).ToList();
                Assert.IsTrue(intersection2.Count == searchResults2.Count);
                Assert.IsTrue(intersection2.Count == createResults.Length);

                //Assert.IsTrue(sw1.Elapsed < sw2.Elapsed);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 12
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));
                }
            }
        }
Exemplo n.º 13
0
        private static void Main()
        {
            Console.CancelKeyPress += OnCancelKeyPressed;

            try
            {
            #if DEBUG
                File.Delete(DefaultDatabaseFilename);
            #endif

                using (var links = new Links(DefaultDatabaseFilename, 8*1024*1024))
                {
                    InitUTF16(links);

                    var sequences = new Sequences(links);

                    PrintContents(links, sequences);

                    Console.WriteLine("Links server started.");
                    Console.WriteLine("Press CTRL+C or ESC to stop server.");

                    using (var sender = new UdpSender(8888))
                    {
                        MessageHandlerCallback handleMessage = message =>
                        {
                            if (!string.IsNullOrWhiteSpace(message))
                            {
                                Console.WriteLine("R.M.: {0}", message);

                                if (message.EndsWith("?"))
                                    sequences.Search(sender, message);
                                else
                                    sequences.Create(sender, message);
                            }
                        };

                        //using (var receiver = new UdpReceiver(7777, handleMessage))
                        using (var receiver = new UdpClient(7777))
                        {
                            while (LinksServerRunning)
                            {
                                while (receiver.Available > 0)
                                    handleMessage(receiver.ReceiveString());

                                while (Console.KeyAvailable)
                                {
                                    var info = Console.ReadKey(true);
                                    if (info.Key == ConsoleKey.Escape)
                                        LinksServerRunning = false;
                                }

                                Thread.Sleep(1);
                            }

                            Console.WriteLine("Links server stopped.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.WriteToConsole();
            }

            Console.CancelKeyPress -= OnCancelKeyPressed;
        }
Exemplo n.º 14
0
        private static void EnsureEachLinkIsAnyOrZeroOrManyOrExists(Links links, params ulong[] sequence)
        {
            if (sequence == null)
                return;

            for (var i = 0; i < sequence.Length; i++)
                if (sequence[i] != Links.Null && sequence[i] != ZeroOrMany && !links.Exists(sequence[i]))
                    throw new ArgumentLinkDoesNotExistsException<ulong>(sequence[i],
                        string.Format("patternSequence[{0}]", i));
        }
Exemplo n.º 15
0
 public Sequences(Links links)
 {
     _links = links;
 }
Exemplo n.º 16
0
        public static void TestDeletionOfAllLinks()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong linksBeforeTest = links.Total;

                Console.WriteLine("Deleting all links");

                TimeSpan elapsedTime = PerformanceHelpers.Measure(links.DeleteAllLinks);

                ulong linksDeleted = linksBeforeTest - links.Total;
                double linksPerSecond = linksDeleted / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} links deleted in {1} ({2} links per second)", linksDeleted, elapsedTime,
                    (long)linksPerSecond);
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 17
0
        public void BasicMemoryTest()
        {
            var tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, 1024 * 1024))
            {
                links.TestBasicMemoryManagement();
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 18
0
        public void BalancedVariantSearchTest()
        {
            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 200;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var sw1 = Stopwatch.StartNew();
                var balancedVariant = sequences.CreateBalancedVariant(sequence); sw1.Stop();

                var sw2 = Stopwatch.StartNew();
                var searchResults2 = sequences.GetAllMatchingSequences0(sequence); sw2.Stop();

                var sw3 = Stopwatch.StartNew();
                var searchResults3 = sequences.GetAllMatchingSequences1(sequence); sw3.Stop();

                // На количестве в 200 элементов это будет занимать вечность
                //var sw4 = Stopwatch.StartNew();
                //var searchResults4 = sequences.Each(sequence); sw4.Stop();

                Assert.IsTrue(searchResults2.Count == 1 && balancedVariant == searchResults2[0]);

                Assert.IsTrue(searchResults3.Count == 1 && balancedVariant == searchResults3.First());

                //Assert.IsTrue(sw1.Elapsed < sw2.Elapsed);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 19
0
        public void CascadeUpdateTest()
        {
            throw new StackOverflowException();

            var tempDatabaseFilename = Path.GetTempFileName();
            var tempTransactionLogFilename = Path.GetTempFileName();

            const ulong itself = Links.Itself;

            using (var links = new Links(tempDatabaseFilename,
                    tempTransactionLogFilename, 1024 * 1024))
            {
                var l1 = links.Create(itself, itself);
                var l2 = links.Create(itself, itself);

                l2 = links.Update(l2, l2, l1, l2);

                links.Create(l2, itself);
                links.Create(l2, itself);

                l2 = links.Update(l2, l1);

                links.Delete(l2);

                Global.Trash = links.Total;
            }

            Global.Trash = FileHelpers
                .ReadAll<Links.Transition>(tempTransactionLogFilename);

            File.Delete(tempDatabaseFilename);
            File.Delete(tempTransactionLogFilename);
        }
Exemplo n.º 20
0
        public void CalculateAllUsagesTest()
        {
            InitBitString();

            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 3;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var createResults = sequences.CreateAllVariants2(sequence);

                //var reverseResults = sequences.CreateAllVariants2(sequence.Reverse().ToArray());

                for (var i = 0; i < 1; i++)
                {
                    var linksTotalUsages1 = new ulong[links.Total + 1];

                    sequences.CalculateAllUsages(linksTotalUsages1);

                    var linksTotalUsages2 = new ulong[links.Total + 1];

                    sequences.CalculateAllUsages2(linksTotalUsages2);

                    var intersection1 = linksTotalUsages1.Intersect(linksTotalUsages2).ToList();
                    Assert.IsTrue(intersection1.Count == linksTotalUsages2.Length);
                }

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

            File.Delete(tempFilename);
        }
Exemplo n.º 21
0
        public void PathsTest()
        {
            var tempDatabaseFilename = Path.GetTempFileName();
            var tempTransactionLogFilename = Path.GetTempFileName();

            const ulong itself = Links.Itself;
            const Links.PathElement source = Links.PathElement.Source;
            const Links.PathElement target = Links.PathElement.Target;

            using (var links = new Links(tempDatabaseFilename, tempTransactionLogFilename, 1024 * 1024))
            {
                var l1 = links.Create(itself, itself);
                var l2 = links.Create(itself, itself);

                var r1 = links.Get(l1, source, target, source);
                var r2 = links.Get(l2, l2, l2, l2);
            }

            File.Delete(tempDatabaseFilename);
            File.Delete(tempTransactionLogFilename);
        }
Exemplo n.º 22
0
        public void CreateAllVariantsTest()
        {
            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 8;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var sw1 = Stopwatch.StartNew();
                var results1 = sequences.CreateAllVariants1(sequence); sw1.Stop();

                var sw2 = Stopwatch.StartNew();
                var results2 = sequences.CreateAllVariants2(sequence); sw2.Stop();

                Assert.IsTrue(results1.Count > results2.Length);
                Assert.IsTrue(sw1.Elapsed > sw2.Elapsed);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 23
0
        public void TestGetTarget()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                Console.WriteLine("Testing GetTarget 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.GetTarget(firstLink);

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = Iterations / elapsedTime.TotalSeconds;

                links.Delete(firstLink);

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

            File.Delete(tempFilename);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        public void TestRandomSearchAll()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong counter = 0;

                ulong minLink = 1UL;
                ulong maxLink = links.Total;

                ulong iterations = links.Total;
                var rnd = new Random((int)DateTime.UtcNow.Ticks);

                Console.WriteLine("Testing Random Search with {0} Iterations.", links.Total);

                Stopwatch sw = Stopwatch.StartNew();

                for (ulong i = iterations; i > 0; i--)
                {
                    ulong source = rnd.NextUInt64(minLink, maxLink);
                    ulong target = rnd.NextUInt64(minLink, maxLink);

                    counter += links.Search(source, target);
                }

                TimeSpan elapsedTime = sw.Elapsed;

                double iterationsPerSecond = iterations / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} Iterations of Random Search done in {1} ({2} Iterations per second), c: {3}",
                    iterations, elapsedTime, (long)iterationsPerSecond, counter);
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 26
0
        public void AllPossibleConnectionsTest()
        {
            InitBitString();

            string tempFilename = Path.GetTempFileName();

            const long sequenceLength = 5;

            const ulong itself = Links.Itself;

            using (var links = new Links(tempFilename, LinksSizeStep))
            {
                var sequence = new ulong[sequenceLength];
                for (int i = 0; i < sequenceLength; i++)
                    sequence[i] = links.Create(itself, itself);

                var sequences = new Sequences(links);

                var createResults = sequences.CreateAllVariants2(sequence);

                var reverseResults = sequences.CreateAllVariants2(sequence.Reverse().ToArray());

                for (var i = 0; i < 1; i++)
                {
                    var sw1 = Stopwatch.StartNew();
                    var searchResults1 = sequences.GetAllConnections(sequence); sw1.Stop();

                    var sw2 = Stopwatch.StartNew();
                    var searchResults2 = sequences.GetAllConnections1(sequence); sw2.Stop();

                    var sw3 = Stopwatch.StartNew();
                    var searchResults3 = sequences.GetAllConnections2(sequence); sw3.Stop();

                    var sw4 = Stopwatch.StartNew();
                    var searchResults4 = sequences.GetAllConnections3(sequence); sw4.Stop();

                    Global.Trash = searchResults3;
                    Global.Trash = searchResults4;

                    var intersection1 = createResults.Intersect(searchResults1).ToList();
                    Assert.IsTrue(intersection1.Count == createResults.Length);

                    var intersection2 = reverseResults.Intersect(searchResults1).ToList();
                    Assert.IsTrue(intersection2.Count == reverseResults.Length);

                    var intersection0 = searchResults1.Intersect(searchResults2).ToList();
                    Assert.IsTrue(intersection0.Count == searchResults2.Count);

                    var intersection3 = searchResults2.Intersect(searchResults3).ToList();
                    Assert.IsTrue(intersection3.Count == searchResults3.Count);

                    var intersection4 = searchResults3.Intersect(searchResults4).ToList();
                    Assert.IsTrue(intersection4.Count == searchResults4.Count);
                }

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

            File.Delete(tempFilename);
        }
Exemplo n.º 27
0
        public static void Create64BillionLinks()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong linksBeforeTest = links.Total;

                long linksToCreate = 64 * 1024 * 1024 / Links.LinkSizeInBytes;

                Console.WriteLine("Creating {0} links.", linksToCreate);

                TimeSpan elapsedTime = PerformanceHelpers.Measure(() =>
                {
                    for (long i = 0; i < linksToCreate; i++)
                    {
                        links.Create(0, 0);
                    }
                });

                ulong linksCreated = links.Total - linksBeforeTest;
                double linksPerSecond = linksCreated / elapsedTime.TotalSeconds;

                Console.WriteLine("Current links count: {0}.", links.Total);

                Console.WriteLine("{0} links created in {1} ({2} links per second)", linksCreated, elapsedTime,
                    (long)linksPerSecond);
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 28
0
        public static void Create64BillionLinksInParallel()
        {
            string tempFilename = Path.GetTempFileName();

            using (var links = new Links(tempFilename, DefaultLinksSize))
            {
                ulong linksBeforeTest = links.Total;

                Stopwatch sw = Stopwatch.StartNew();

                long linksToCreate = 64 * 1024 * 1024 / Links.LinkSizeInBytes;

                Console.WriteLine("Creating {0} links in parallel.", linksToCreate);

                Parallel.For(0, linksToCreate, x => links.Create(0, 0));

                TimeSpan elapsedTime = sw.Elapsed;

                ulong linksCreated = links.Total - linksBeforeTest;
                double linksPerSecond = linksCreated / elapsedTime.TotalSeconds;

                Console.WriteLine("{0} links created in {1} ({2} links per second)", linksCreated, elapsedTime,
                    (long)linksPerSecond);
            }

            File.Delete(tempFilename);
        }
Exemplo n.º 29
0
 public LinksSourcesTreeMethods(Links links, LinksHeader* header)
 {
     _db = links;
     _links = links._links;
     _header = header;
 }
Exemplo n.º 30
0
 public AllUsagesCollector2(Links links, BitString usages)
 {
     _links = links;
     _usages = usages;
 }