Exemplo n.º 1
0
        public EwahCompressedBitArray query(BICriteria criteria)
        {
            // This method could use recursion which would make it more readable
            // For performance reasons, and to avoid StackOverflowException, it
            // uses the Snapshot class to avoid recursion

            if (criteria == null)
            {
                throw new ArgumentNullException("criteria");
            }

            EwahCompressedBitArray temp;
            Snapshot previous;
            Snapshot next;

            Snapshot current = new Snapshot();

            current.criteria = criteria;
            current.state    = 0;

            Stack <Snapshot> stack = new Stack <Snapshot>();

            stack.Push(current);

            while (stack.Count > 0)
            {
                current = stack.Pop();

                if (stack.Count > 0)
                {
                    previous = stack.Peek();
                }
                else
                {
                    previous = null;
                }

                if (current.criteria.CriteriaOperator == BICriteria.Operator.OR ||
                    current.criteria.CriteriaOperator == BICriteria.Operator.AND)
                {
                    if (current.state == 0)
                    {
                        current.state = 1;
                        stack.Push(current);

                        next          = new Snapshot();
                        next.criteria = current.criteria.LeftCriteria;
                        next.state    = 0;
                        stack.Push(next);

                        continue;
                    }
                    else if (current.state == 1)
                    {
                        current.state = 2;
                        stack.Push(current);

                        next          = new Snapshot();
                        next.criteria = current.criteria.RightCriteria;
                        next.state    = 0;
                        stack.Push(next);

                        continue;
                    }
                    else
                    {
                        if (current.criteria.CriteriaOperator == BICriteria.Operator.AND)
                        {
                            temp = (current.left.And(current.right));
                        }
                        else
                        {
                            temp = (current.left.Or(current.right));
                        }

                        if (previous == null)
                        {
                            return(temp);
                        }
                        else if (previous.state == 1)
                        {
                            previous.left = temp;
                        }
                        else if (previous.state == 2)
                        {
                            previous.right = temp;
                        }

                        continue;
                    }
                }
                else
                {
                    if (current.criteria.CriteriaOperator == BICriteria.Operator.EMPTY_ONLY)
                    {
                        if (previous == null)
                        {
                            return(getEmptyBitmap(current.criteria.Key));
                        }
                        else if (previous.state == 1)
                        {
                            previous.left = getEmptyBitmap(current.criteria.Key);
                        }
                        else if (previous.state == 2)
                        {
                            previous.right = getEmptyBitmap(current.criteria.Key);
                        }

                        continue;
                    }
                    else
                    {
                        EwahCompressedBitArray bitmap;

                        if (!_bitmaps.ContainsKey(current.criteria.Key))
                        {
                            bitmap = getFilledBitmap(false);
                        }
                        else
                        {
                            bitmap = getCopyBitmap(_bitmaps[current.criteria.Key]);
                        }

                        if (current.criteria.CriteriaOperator == BICriteria.Operator.NOT_EQUALS ||
                            current.criteria.CriteriaOperator == BICriteria.Operator.NOT_EQUALS_OR_EMPTY)
                        {
                            bitmap.Not();
                        }

                        if (current.criteria.CriteriaOperator == BICriteria.Operator.NOT_EQUALS_OR_EMPTY ||
                            current.criteria.CriteriaOperator == BICriteria.Operator.EQUALS_OR_EMPTY)
                        {
                            bitmap = bitmap.Or(getEmptyBitmap(current.criteria.Key));
                        }

                        if (previous == null)
                        {
                            return(bitmap);
                        }
                        else if (previous.state == 1)
                        {
                            previous.left = bitmap;
                        }
                        else if (previous.state == 2)
                        {
                            previous.right = bitmap;
                        }

                        continue;
                    }
                }
            }

            temp = new EwahCompressedBitArray();
            temp.SetSizeInBits(_maxBitSize, false);
            return(temp);
        }
Exemplo n.º 2
0
 public BICriteria or(BICriteria criteria)
 {
     return(new BICriteria(this, criteria, Operator.OR));
 }
Exemplo n.º 3
0
 public BICriteria and(BICriteria criteria)
 {
     return(new BICriteria(this, criteria, Operator.AND));
 }
Exemplo n.º 4
0
 private BICriteria(BICriteria left, BICriteria right, Operator criteriaOperator)
 {
     _left             = left;
     _right            = right;
     _criteriaOperator = criteriaOperator;
 }
 private BICriteria(BICriteria left, BICriteria right, Operator criteriaOperator)
 {
     _left = left;
     _right = right;
     _criteriaOperator = criteriaOperator;
 }
 public BICriteria or(BICriteria criteria)
 {
     return new BICriteria(this, criteria, Operator.OR);
 }
 public BICriteria and(BICriteria criteria)
 {
     return new BICriteria(this, criteria, Operator.AND);
 }
        public EwahCompressedBitArray query(BICriteria criteria)
        {
            // This method could use recursion which would make it more readable
            // For performance reasons, and to avoid StackOverflowException, it
            // uses the Snapshot class to avoid recursion

            if (criteria == null)
                throw new ArgumentNullException("criteria");

            EwahCompressedBitArray temp;
            Snapshot previous;
            Snapshot next;

            Snapshot current = new Snapshot();
            current.criteria = criteria;
            current.state = 0;

            Stack<Snapshot> stack = new Stack<Snapshot>();
            stack.Push(current);

            while (stack.Count > 0)
            {
                current = stack.Pop();

                if (stack.Count > 0)
                    previous = stack.Peek();
                else
                    previous = null;

                if (current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.OR ||
                    current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.AND)
                {
                    if (current.state == 0)
                    {
                        current.state = 1;
                        stack.Push(current);

                        next = new Snapshot();
                        next.criteria = current.criteria.LeftCriteria;
                        next.state = 0;
                        stack.Push(next);

                        continue;
                    }
                    else if (current.state == 1)
                    {
                        current.state = 2;
                        stack.Push(current);

                        next = new Snapshot();
                        next.criteria = current.criteria.RightCriteria;
                        next.state = 0;
                        stack.Push(next);

                        continue;
                    }
                    else
                    {
                        if (current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.AND)
                            temp = (current.left.And(current.right));
                        else
                            temp = (current.left.Or(current.right));

                        if (previous == null)
                        {
                            return temp;
                        }
                        else if (previous.state == 1)
                        {
                            previous.left = temp;
                        }
                        else if (previous.state == 2)
                        {
                            previous.right = temp;
                        }

                        continue;
                    }
                }
                else
                {
                    if (current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.EMPTY_ONLY)
                    {
                        if (previous == null)
                            return getEmptyBitmap(current.criteria.Key);
                        else if (previous.state == 1)
                            previous.left = getEmptyBitmap(current.criteria.Key);
                        else if (previous.state == 2)
                            previous.right = getEmptyBitmap(current.criteria.Key);

                        continue;
                    }
                    else
                    {
                        EwahCompressedBitArray bitmap;

                        if (!_bitmaps.ContainsKey(current.criteria.Key))
                            bitmap = getFilledBitmap(false);
                        else
                            bitmap = getCopyBitmap(_bitmaps[current.criteria.Key]);

                        if (current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.NOT_EQUALS ||
                            current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.NOT_EQUALS_OR_EMPTY)
                            bitmap.Not();

                        if (current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.NOT_EQUALS_OR_EMPTY ||
                            current.criteria.CriteriaOperator == BusinessLayer.Uteis.BICriteria.Operator.EQUALS_OR_EMPTY)
                            bitmap = bitmap.Or(getEmptyBitmap(current.criteria.Key));

                        if (previous == null)
                            return bitmap;
                        else if (previous.state == 1)
                            previous.left = bitmap;
                        else if (previous.state == 2)
                            previous.right = bitmap;

                        continue;
                    }
                }
            }

            temp = new EwahCompressedBitArray();
            temp.SetSizeInBits(_maxBitSize, false);
            return temp;
        }