public IAdd ( ushort begin, ushort end ) : Container | ||
begin | ushort | Start of range |
end | ushort | End of range |
return | Container |
/// <summary> /// Adds range of elements (in-place) to this container. /// </summary> /// <param name="begin">Start of range (inclusive)</param> /// <param name="end">End of range (exclusive)</param> /// <returns>Modified container</returns> public override Container IAdd(ushort begin, ushort end) { // TODO: may need to convert to a RunContainer if (end == begin) { return(this); } if (begin > end) { throw new ArgumentException("Invalid range [" + begin + "," + end + ")"); } int indexStart = Utility.UnsignedBinarySearch(Content, 0, Cardinality, begin); if (indexStart < 0) { indexStart = -indexStart - 1; } int indexEnd = Utility.UnsignedBinarySearch(Content, 0, Cardinality, (ushort)(end - 1)); if (indexEnd < 0) { indexEnd = -indexEnd - 1; } else { indexEnd++; } int rangeLength = end - begin; int newCardinality = indexStart + (Cardinality - indexEnd) + rangeLength; if (newCardinality > DEFAULT_MAX_SIZE) { BitsetContainer a = ToBitsetContainer(); return(a.IAdd(begin, end)); } if (newCardinality >= Content.Length) { IncreaseCapacity(newCardinality); } Array.Copy(Content, indexEnd, Content, indexStart + rangeLength, Cardinality - indexEnd); for (int k = 0; k < rangeLength; ++k) { Content[k + indexStart] = (ushort)(begin + k); } Cardinality = newCardinality; return(this); }