private static void PlainSearch(string src, string sub) { RkSearch rksearch = new RkSearch(); SimpleSearch ssearch = new SimpleSearch(); DumbSearch dsearch = new DumbSearch(); DateTime start, end; int idx = 0; Console.WriteLine("Searching"); Console.WriteLine("Dumb Search ... "); start = DateTime.Now; idx = dsearch.Search(src, sub); end = DateTime.Now; Console.WriteLine("Dumb Search Time: {0}ms", (end - start).TotalMilliseconds); Console.WriteLine("Index: {0}", idx); Console.WriteLine("Simple Search ... "); start = DateTime.Now; idx = ssearch.Search(src, sub); end = DateTime.Now; Console.WriteLine("Simple Search Time: {0}ms", (end - start).TotalMilliseconds); Console.WriteLine("Index: {0}", idx); Console.WriteLine("Rabin Karp Search ... "); start = DateTime.Now; idx = rksearch.Search(src, sub); end = DateTime.Now; Console.WriteLine("RK Search Time: {0}ms", (end - start).TotalMilliseconds); Console.WriteLine("Index: {0}", idx); }
public void RkSimpleSearchCompareTest() { RkSearch rksearch = new RkSearch(); SimpleSearch ssearch = new SimpleSearch(); SeqUtils gen = new SeqUtils(); string src = gen.GenerateSequence(1000); string sub = src.Substring(850, 15); int idx = 0; Console.WriteLine(src.Length); DateTime start, end; start = DateTime.Now; idx = ssearch.Search(src, sub); end = DateTime.Now; Console.WriteLine("Simple Search Time: {0}ms", (end - start).TotalMilliseconds); Console.WriteLine("Index: {0}", idx); start = DateTime.Now; idx = rksearch.Search(src, sub); end = DateTime.Now; Console.WriteLine("RK Search Time: {0}ms", (end - start).TotalMilliseconds); Console.WriteLine("Index: {0}", idx); }
public void RkSearchTestset() { RkSearch search = new RkSearch(); ulong x = 25223; int c = search.CountSetPairs2(x); Assert.AreEqual(c, 6); x = 10578; c = search.CountSetPairs2(x); Assert.AreEqual(c, 6); }
public void RkSearchTestSetMany() { RkSearch search = new RkSearch(); for (ulong i = ulong.MaxValue - 20000000; i > ulong.MaxValue - 4000; i--) { Console.WriteLine(i); int c1 = search.CountSetPairs(i); int c2 = search.CountSetPairs2(i); Console.WriteLine("C1: {0} C2: {1}", c1, c2); Assert.AreEqual(c1, c2); } }
public void RkSearchRandomSequence() { SeqUtils gen = new SeqUtils(); string src = gen.GenerateSequence(1000); // 13 is the max limit due to size of long string sub = src.Substring(900, 23); RkSearch search = new RkSearch(); int idx = search.Search(src, sub); Assert.IsTrue(idx > 0); Assert.IsTrue(idx == 900); }
private static void BasicDemo() { RkSearch rksearch = new RkSearch(); SimpleSearch ssearch = new SimpleSearch(); DumbSearch dsearch = new DumbSearch(); SeqUtils gen = new SeqUtils(); int seqLen = 200000000; Console.Write("Generating sequence of length {0} ....", seqLen); string src = gen.GenerateSequence(200000000); Console.WriteLine("Done."); int subPos = 85000001; int subLen = 25; Console.WriteLine("Substring of length {0} and at position {1}", subLen, subPos); string sub = src.Substring(85000001, 25); PlainSearch(src, sub); int diff = 4; sub = gen.InsertDiff(sub, diff); DiffSearch(src, sub, diff); }
public void RkSearchTest() { string src = "acgtaaactgggacct"; string sub = "ctg"; RkSearch search = new RkSearch(); int idx = search.Search(src, sub); Assert.IsTrue(idx > 0); Assert.IsTrue(idx == 7); Console.WriteLine("Found at {0}", idx); sub = "a"; idx = search.Search(src, sub); Assert.IsTrue(idx >= 0); Assert.IsTrue(idx == 0); sub = "acct"; idx = search.Search(src, sub); Assert.IsTrue(idx >= 0); Assert.IsTrue(idx == src.Length - sub.Length); sub = "tttt"; idx = search.Search(src, sub); Assert.IsTrue(idx < 0); }
private static void ThreeBillionRkSearch() { RkSearch rksearch = new RkSearch(); SeqUtils util = new SeqUtils(); SimpleSearch ssearch = new SimpleSearch(); // We generate really large strings, which total up to 3 billion in the end. // The substring which we are searching for is 27 characters in length string sub = util.GenerateSequence(27); List<int> rkmatch = new List<int>(); List<int> ssmatch = new List<int>(); TimeSpan rkspan = TimeSpan.Zero, sspan = TimeSpan.Zero; DateTime start, end; for (int i = 0; i < 10; i++) { Console.WriteLine("Iteration {0}", i); for (int j = 0; j < 3000; j++) { string src = util.GenerateSequence(1000000); start = DateTime.Now; rkmatch.AddRange(rksearch.SearchWithDiffAll(src, sub, 5)); end = DateTime.Now; rkspan += (end - start); start = DateTime.Now; ssmatch.AddRange(ssearch.SearchWithDiffAll(src, sub, 5)); end = DateTime.Now; sspan += (end - start); src = null; } } Console.WriteLine("Rabin Karp Time taken: {0} s", rkspan.TotalSeconds); for (int i = 0; i < rkmatch.Count; i++) { Console.WriteLine(rkmatch[i]); } Console.WriteLine("Simple Search Time Taken: {0} s", sspan.TotalSeconds); for (int i = 0; i < rkmatch.Count; i++) { Console.WriteLine(ssmatch[i]); } bool equal = true; for (int i = 0; i < rkmatch.Count; i++) { if (rkmatch[i] != ssmatch[i]) { equal = false; break; } } Console.WriteLine("Rabin Karp and Simple Search matches are equal: {0}", equal); }
public void RkSearchWithDiff() { SeqUtils util = new SeqUtils(); string src = util.GenerateSequence(1000); string sub = src.Substring(900, 23); RkSearch search = new RkSearch(); sub = util.InsertDiff(sub, 5); int idx = search.SearchWithDiff(src, sub, 5); Assert.IsTrue(idx > 0); }