Exemplo n.º 1
0
        public void BitwiseAnd(IBitVector u)
        {
            BitVectorAlloc v = (BitVectorAlloc)u;

            Ensure.That(v).IsNotNull();
            Ensure.That(Size).Is(v.Size);

            if (!allocated && !v.allocated)
            {
                return;
            }

            if (allocated && !v.allocated)
            {
                Deallocate();
                return;
            }

            if (!allocated && v.allocated)
            {
                return;
            }

            bool isEmpty = true;

            unsafe
            {
                fixed(UInt64 *items_ptr = items)
                {
                    fixed(UInt64 *v_items_ptr = v.items)
                    {
                        UInt64 *items_last   = items_ptr + items.Length;
                        UInt64 *v2items_last = v_items_ptr + v.items.Length;

                        UInt64 *ptr   = items_ptr;
                        UInt64 *v_ptr = v_items_ptr;

                        for (; ptr < items_last;)
                        {
                            (*ptr) &= (*v_ptr);

                            if ((*ptr) != 0)
                            {
                                isEmpty = false;
                            }

                            ptr++;
                            v_ptr++;
                        }
                    }
                }
            }

            if (isEmpty)
            {
                Deallocate();
            }
        }
Exemplo n.º 2
0
        public BitVectorAlloc(BitVectorAlloc v)
        {
            Size      = v.Size;
            wordCount = v.wordCount;

            if (v.allocated)
            {
                Allocate();
                v.items.CopyTo(items, 0);
            }
        }
Exemplo n.º 3
0
        public override bool Equals(Object?obj)
        {
            BitVectorAlloc v = (BitVectorAlloc)obj !;

            Ensure.That(v).IsNotNull();
            Ensure.That(Size).Is(v.Size);

            if (!allocated && !v.allocated)
            {
                return(true);
            }

            if (!allocated && v.allocated)
            {
                return(v.items.All(p => p == 0));
            }

            if (allocated && !v.allocated)
            {
                return(items.All(p => p == 0));
            }

            return(items.SequenceEqual(v.items));
        }
Exemplo n.º 4
0
        public IBitVector BitwiseAnd(IBitVector x, IBitVector y)
        {
            BitVectorAlloc v1 = (BitVectorAlloc)x;
            BitVectorAlloc v2 = (BitVectorAlloc)y;

            Ensure.That(v1).IsNotNull();
            Ensure.That(v2).IsNotNull();

            Ensure.That(v1.Size).Is(v2.Size);

            BitVectorAlloc result = new(v1.Size);

            if (!v1.allocated && !v2.allocated)
            {
                return(result);
            }

            if (v1.allocated && !v2.allocated)
            {
                return(result);
            }

            if (!v1.allocated && v2.allocated)
            {
                return(result);
            }

            result.Allocate();

            unsafe
            {
                fixed(UInt64 *r_items_ptr = result.items)
                {
                    fixed(UInt64 *v1_items_ptr = v1.items)
                    {
                        fixed(UInt64 *v2_items_ptr = v2.items)
                        {
                            UInt64 *r_items_last  = r_items_ptr + result.items.Length;
                            UInt64 *v1_items_last = v1_items_ptr + v1.items.Length;
                            UInt64 *v2_items_last = v2_items_ptr + v2.items.Length;

                            UInt64 *r_ptr  = r_items_ptr;
                            UInt64 *v1_ptr = v1_items_ptr;
                            UInt64 *v2_ptr = v2_items_ptr;

                            for (; v1_ptr < v1_items_last;)
                            {
                                (*r_ptr) = (*v1_ptr) & (*v2_ptr);

                                r_ptr++;
                                v1_ptr++;
                                v2_ptr++;
                            }
                        }
                    }
                }
            }

            if (result.IsEmpty())
            {
                return(new BitVectorAlloc(v1.Size));
            }

            return(result);
        }