/// <summary> /// Remove from the current bitmap all integers in [rangeStart,rangeEnd). /// </summary> /// <param name="rangeStart">inclusive beginning of range</param> /// <param name="rangeEnd">exclusive ending of range</param> public void Remove(int rangeStart, int rangeEnd) { if (rangeStart >= rangeEnd) { return; // empty range } ushort hbStart = Utility.GetHighBits(rangeStart); ushort lbStart = Utility.GetLowBits(rangeStart); ushort hbLast = Utility.GetHighBits(rangeEnd - 1); ushort lbLast = Utility.GetLowBits(rangeEnd - 1); if (hbStart == hbLast) { int containerIndex = containers.GetIndex(hbStart); if (containerIndex < 0) { return; } Container c = containers.GetContainerAtIndex(containerIndex) .Remove(lbStart, (ushort)(lbLast + 1)); if (c.GetCardinality() > 0) { containers.SetContainerAtIndex(containerIndex, c); } else { containers.RemoveAtIndex(containerIndex); } return; } int ifirst = containers.GetIndex(hbStart); int ilast = containers.GetIndex(hbLast); if (ifirst >= 0) { if (lbStart != 0) { Container c = containers.GetContainerAtIndex(ifirst) .Remove(lbStart, ushort.MaxValue); if (c.GetCardinality() > 0) { containers.SetContainerAtIndex(ifirst, c); ifirst++; } } } else { ifirst = -ifirst - 1; } if (ilast >= 0) { if (lbLast != ushort.MaxValue) { Container c = containers.GetContainerAtIndex(ilast) .Remove(0, (ushort)(lbLast + 1)); if (c.GetCardinality() > 0) { containers.SetContainerAtIndex(ilast, c); } else { ilast++; } } else { ilast++; } } else { ilast = -ilast - 1; } containers.RemoveIndexRange(ifirst, ilast); }