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 override Expression Visit(Expression node) { if (node.NodeType == ExpressionType.NewArrayInit) { var a = node as NewArrayExpression; _count = a.Expressions.Count; return(base.Visit(node)); } else if (node.NodeType == ExpressionType.MemberAccess) { var v = base.Visit(node); if (_InCommand != "") { var a = _stack.Pop() as IList; foreach (var c in a) { if (_inBmp == null) { _inBmp = qexpression(_InCommand, RDBExpression.Equal, c); } else { _inBmp = _inBmp.Or(qexpression(_InCommand, RDBExpression.Equal, c)); } } } return(v); } else { return(base.Visit(node)); } }
public static void Or() { var list = CreateList(10000, 1000 * 1000); 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); var c = zz.CountOnes(); Assert.AreEqual(list.Count * 2, c); }
public static void OptimizeTest() { // optimize var op1 = new MGRB(); op1.Set(100, true); op1.Set(1000, true); op1.Set(2000, true); op1.Set(100000, true); op1.Set(50000, true); op1.Set(55000, true); op1.Set(60000, true); op1.Set(3000, true); op1.Set(51000, true); op1.Set(100000, false); op1.Optimize(); }
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); }
public static void SmallValuesLength() { var a = new MGRB(); var r = new Random(); for (int i = 0; i < 100; i++) { a.Set(r.Next(10000), true); } var b = MGRB.Fill(20000); var p = a.Or(b); var c = p.CountOnes(); Assert.AreEqual(b.Length, p.Length); var o = a.And(b); Assert.AreEqual(a.Length, o.Length); }
public static void SerializeDeserialize() { var list = CreateList(10000, 1000 * 1000); var y = new MGRB(); foreach (var l in list) { y.Set(l.Key, true); } var o = y.Serialize(); var z = new MGRB(); z.Deserialize(o); var a = y.AndNot(z); a.Optimize(); var c = a.CountOnes(); Assert.AreEqual(0, c); }
protected override Expression VisitConstant(ConstantExpression c) { IQueryable q = c.Value as IQueryable; if (q != null) { _stack.Push(q.ElementType.Name); } else if (c.Value == null) { _stack.Push(null); } else { Type t = c.Value.GetType(); if (t.IsValueType || t == typeof(string)) { if (_InCommand != "") { if (_inBmp == null) { _inBmp = qexpression(_InCommand, RDBExpression.Equal, c.Value); } else { _inBmp = _inBmp.Or(qexpression(_InCommand, RDBExpression.Equal, c.Value)); } } else { _stack.Push(c.Value); } } } return(c); }
protected override Expression VisitBinary(BinaryExpression b) { _leftmode = true; var m = this.Visit(b.Left); if (m == null) // VB.net sty;e linq for string compare { return(b.Right); } ExpressionType t = b.NodeType; if (t == ExpressionType.Equal || t == ExpressionType.NotEqual || t == ExpressionType.LessThan || t == ExpressionType.LessThanOrEqual || t == ExpressionType.GreaterThan || t == ExpressionType.GreaterThanOrEqual) { _stack.Push(b.NodeType); } _leftmode = false; this.Visit(b.Right); t = b.NodeType; if (t == ExpressionType.Equal || t == ExpressionType.NotEqual || t == ExpressionType.LessThanOrEqual || t == ExpressionType.LessThan || t == ExpressionType.GreaterThanOrEqual || t == ExpressionType.GreaterThan ) { // binary expression object lval = _stack.Pop(); ExpressionType lop = (ExpressionType)_stack.Pop(); string lname = (string)_stack.Pop(); if (_stack.Count > 0) { lname += "_" + (string)_stack.Pop(); } RDBExpression exp = RDBExpression.Equal; if (lop == ExpressionType.LessThan) { exp = RDBExpression.Less; } else if (lop == ExpressionType.LessThanOrEqual) { exp = RDBExpression.LessEqual; } else if (lop == ExpressionType.GreaterThan) { exp = RDBExpression.Greater; } else if (lop == ExpressionType.GreaterThanOrEqual) { exp = RDBExpression.GreaterEqual; } else if (lop == ExpressionType.NotEqual) { exp = RDBExpression.NotEqual; } _bitmap.Push(qexpression(lname, exp, lval)); } if (t == ExpressionType.And || t == ExpressionType.AndAlso || t == ExpressionType.Or || t == ExpressionType.OrElse) { if (_bitmap.Count > 1) { // do bitmap operations MGRB right = (MGRB)_bitmap.Pop(); MGRB left = (MGRB)_bitmap.Pop(); if (t == ExpressionType.And || t == ExpressionType.AndAlso) { _bitmap.Push(right.And(left)); } if (t == ExpressionType.Or || t == ExpressionType.OrElse) { _bitmap.Push(right.Or(left)); } } else { // single bitmap operation } } return(b); }
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(); }