예제 #1
0
        public SparseBitset AndNot(SparseBitset b, SparseBitset fullBitset)
        {
            SparseBitset result;

            var bb = (SparseBitset)b;
            var fb = (SparseBitset)fullBitset;

            //if (IsOptimized && this.IsOptimized)
            //{
            result = SparseBitsetOptimzedOperators.And(this, SparseBitsetOptimzedOperators.Not(bb, fb));
            //}
            //else
            //{
            //    result = new SparseBitset();
            //    foreach (var bitWord in fb.Where(x => !bb.ContainsKey(x.Key)))
            //    {
            //        result.Add(bitWord.Key, bitWord.Value);
            //    }

            //    // We need to AND against the fullBitset valuepair in case we flipped a bit to 1 in a position
            //    // that doesn't exist in the full bitset

            //    foreach (var bitWord in this.Where(x => bb.ContainsKey(x.Key)))
            //    {
            //        result.Add(bitWord.Key, bitWord.Value & ~bb[bitWord.Key] & fb[bitWord.Key]);
            //    }
            //}


            return(result);
        }
예제 #2
0
        public SparseBitset Or(SparseBitset b)
        {
            SparseBitset result;
            var          bb = (SparseBitset)b;

            // Where the bitset keys do overlap, bits should be an AND of the bits in A and B
            //if (this.IsOptimized && bb.IsOptimized)
            //{
            result = SparseBitsetOptimzedOperators.Or(this, bb);
            //}
            //else
            //{
            //    result = new SparseBitset();

            //    foreach (var bitWord in this)
            //    {
            //        if (bb.TryGetValue(bitWord.Key, out ulong value))
            //        {
            //            result.Add(bitWord.Key, bitWord.Value & value);
            //        }
            //    }

            //    foreach (var bitWord in bb.Where(x => !this.ContainsKey(x.Key)))
            //    {
            //        this.Add(bitWord.Key, bitWord.Value);
            //    }
            //}

            // Where the bitset keys do not overlap, bits will automatically be zero
            // so there is no need to check the

            return(result);
        }
예제 #3
0
        public SparseBitset Not(SparseBitset fullBitset)
        {
            SparseBitset result;

            var fb = (SparseBitset)fullBitset;


            //if (this.IsOptimized && fb.IsOptimized)
            //{
            result = SparseBitsetOptimzedOperators.Not(this, fb);
            //}
            //else
            //{
            //    result = new SparseBitset();
            //    // Because the bitsets are sparse, the whole range of bitsets is not stored.
            //    // This makes it impossible to perform a correct NOT without the full bitset

            //    // First, we need to copy the bit fields that are in the fullbitset but are not in
            //    // the source bitset. This is equivalent to flipping the non-existant bits in the source
            //    // bitset that exist in the range off the full bitset.

            //    foreach (var bitWord in fb.Where(x => !this.ContainsKey(x.Key)))
            //    {
            //        result.Add(bitWord.Key, bitWord.Value);
            //    }

            //    // Next we copy in the inverse of the bit fields from our source, but also AND
            //    // each bitfield with the corresponding field in the full bitset to remove invalid bits

            //    foreach (var bitWord in this)
            //    {
            //        result.Add(bitWord.Key, ~bitWord.Value & fb[bitWord.Key]);
            //    }


            //}

            return(result);
        }