Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
        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);
        }