// a.AndNot(b) == a And !b public FastSparseBitArray AndNot(FastSparseBitArray other) { FastSparseBitArray res = new FastSparseBitArray(); int pos = 0; int otherPos = 0; int itemCount = maxUsedPos; int otherItemCount = other.maxUsedPos; while ((pos < itemCount) && (otherPos < otherItemCount)) { if (keys[pos] < other.keys[otherPos]) { res.Insert(res.maxUsedPos, keys[pos]); res.values[res.maxUsedPos - 1] = values[pos]; pos++; } else if (keys[pos] > other.keys[otherPos]) { otherPos++; } else { if ((values[pos] & (~other.values[otherPos])) != 0) { res.Insert(res.maxUsedPos, keys[pos]); res.values[res.maxUsedPos - 1] = (values[pos] & (~other.values[otherPos])); } pos++; otherPos++; } } while (pos < itemCount) { res.Insert(res.maxUsedPos, keys[pos]); res.values[res.maxUsedPos - 1] = values[pos]; pos++; } return(res); }
public FastSparseBitArray Xor(FastSparseBitArray other) { FastSparseBitArray res = new FastSparseBitArray(); int pos = 0; int otherPos = 0; while ((pos < maxUsedPos) || (otherPos < other.maxUsedPos)) { int key; ulong val; if (otherPos == other.maxUsedPos) { key = keys[pos]; val = values[pos]; pos++; } else if (pos == maxUsedPos) { key = other.keys[otherPos]; val = other.values[otherPos]; otherPos++; } else if (keys[pos] < other.keys[otherPos]) { key = keys[pos]; val = values[pos]; pos++; } else if (keys[pos] > other.keys[otherPos]) { key = other.keys[otherPos]; val = other.values[otherPos]; otherPos++; } else { key = keys[pos]; val = values[pos] ^ other.values[otherPos]; pos++; otherPos++; } res.Insert(res.maxUsedPos, key); res.values[res.maxUsedPos - 1] = val; } return(res); }