public static void OR1() { var a = new MGRB(); var b = new MGRB(); for (int i = 0; i < 1000 * 1000; i += 10) { a.Set(1 + i, true); a.Set(3 + i, true); a.Set(5 + i, true); a.Set(7 + i, true); a.Set(9 + i, true); b.Set(0 + i, true); b.Set(2 + i, true); b.Set(4 + i, true); b.Set(6 + i, true); b.Set(8 + i, true); } var o = a.Or(b).Optimize(); var c = o.CountOnes(); Console.WriteLine("a count = " + a.CountOnes()); Console.WriteLine("b count = " + b.CountOnes()); Console.WriteLine("count = " + c); }
public static void And() { var list = CreateList(10000, 1000 * 1000); Console.WriteLine("count = " + list.Count); Stopwatch sw = new Stopwatch(); sw.Start(); MGRB a = new MGRB(); foreach (var l in list) { a.Set(l.Key, true); } sw.Stop(); Console.WriteLine("mgrb set time : " + sw.ElapsedMilliseconds); var ok = true; foreach (var k in a.GetBitIndexes()) { if (a.Get(k) == false) { ok = false; } } a.Optimize(); var c = a.CountOnes(); Console.WriteLine("max list = " + list.Keys.Max()); Console.WriteLine("max bm = " + a.Length); Console.WriteLine("list count = " + list.Count); Console.WriteLine("bm count = " + c); Console.WriteLine(" ok = " + ok); Assert.True(ok); Assert.AreEqual(list.Count, c); Assert.AreEqual(list.Keys.Max(), a.Length); }
static void Main(string[] args) { int count = 100; Global.useSortedList = false; Dictionary <long, bool> list = new Dictionary <long, bool>(); var r = new Random(); for (int i = 0; i < count; i++) { var cc = r.Next(1000 * 1000 * 1);// + 1000*1000; if (list.ContainsKey(cc) == false) { list.Add(cc, true); } } Console.WriteLine("count = " + count); Stopwatch sw = new Stopwatch(); sw.Start(); MGRB a = new MGRB(); foreach (var l in list) { a.Set(l.Key, true); } sw.Stop(); Console.WriteLine("mgrb set time : " + sw.ElapsedMilliseconds); sw.Reset(); sw.Start(); RaptorDB.WAHBitArray w = new RaptorDB.WAHBitArray(); foreach (var l in list) { w.Set((int)l.Key, true); } sw.Stop(); Console.WriteLine("wah set time : " + sw.ElapsedMilliseconds); var ok = true; foreach (var k in a.GetBitIndexes()) { if (a.Get(k) == false) { ok = false; } } a.Optimize(); var c = a.CountOnes(); Console.WriteLine("max list = " + list.Keys.Max()); Console.WriteLine("max bm = " + a.Length); Console.WriteLine("list count = " + list.Count); Console.WriteLine("bm count = " + c); Console.WriteLine(" ok = " + ok); if (ok == false || list.Count != c) { throw new Exception(); } if (list.Keys.Max() != a.Length) { throw new Exception(); } var x = a.AndNot(new MGRB()); x.Optimize(); c = x.CountOnes(); if (list.Count != c) { throw new Exception(); } var y = new MGRB(); var z = new MGRB(); foreach (var l in list) { y.Set(l.Key, true); z.Set(l.Key + 1000000, true); } var zz = y.Or(z); c = zz.CountOnes(); if (y.CountOnes() * 2 != c) { throw new Exception(); } var zn = zz.Not(); zn.Optimize(); var iii = zn.CountOnes(); var o = zz.Serialize(); var s = fastJSON.JSON.ToNiceJSON(o, new fastJSON.JSONParameters { UseExtensions = false }); var mmm = new MGRB(); mmm.Deserialize(o); c = zz.AndNot(mmm).CountOnes(); }