/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> public OrdinalList Clone() { OrdinalList copy = new OrdinalList(); copy._bits = (byte[])_bits.Clone(); return(copy); }
/// <summary> Returns the 1's compliment (inverts) of the list up to Ceiling </summary> public OrdinalList Invert(int ceiling) { unchecked { byte[] copy = new byte[_bits.Length]; for (int i = 0; i < _bits.Length; i++) { copy[i] = (byte)~_bits[i]; } OrdinalList result = new OrdinalList(); result._bits = copy; result.Ceiling = ceiling; int limit = result.Ceiling; for (int i = Ceiling; i < limit; i++) { result.Add(i); } for (int i = ceiling + 1; i <= limit; i++) { result.Remove(i); } return(result); } }
/// <summary> Returns the set of items that are in either this set or the provided set </summary> /// <example>{ 1, 2, 3 }.UnionWith({ 2, 3, 4 }) == { 1, 2, 3, 4 }</example> public OrdinalList UnionWith(OrdinalList other) { byte[] small, big; big = _bits.Length > other._bits.Length ? _bits : other._bits; small = _bits.Length > other._bits.Length ? other._bits : _bits; byte[] newbits = (byte[])big.Clone(); for (int i = 0; i < small.Length; i++) { newbits[i] |= small[i]; } OrdinalList result = new OrdinalList(); result._bits = newbits; return(result); }