RoaringBitmap

public class RoaringBitmap: Sequence, Equatable, CustomStringConvertible,
                           Hashable, ExpressibleByArrayLiteral

Swift wrapper for CRoaring (a C/C++ implementation at https://github.com/RoaringBitmap/CRoaring)

  • Declaration

    Swift

    public typealias Element = UInt32
  • Creates a new bitmap (initially empty)

    Declaration

    Swift

    public init()
  • Add all the values between min (included) and max (excluded) that are at a distance k*step from min.

    Declaration

    Swift

    public init(min: UInt64, max: UInt64, step: UInt32)
  • Creates a new bitmap (initially empty) with a provided container-storage capacity (it is a performance hint).

    Declaration

    Swift

    public init(capacity: UInt32)
  • Creates a new bitmap from a pointer of UInt32 integers

    Declaration

    Swift

    public init(values: [UInt32])
  • Declaration

    Swift

    public required init(arrayLiteral: Element...)
  • Computes the intersection between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public func intersection(_ x: RoaringBitmap) -> RoaringBitmap
  • Computes the intersection between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public static func & (left: RoaringBitmap, right: RoaringBitmap) -> RoaringBitmap
  • Inplace version modifies x1, x1 == x2 is allowed

    Declaration

    Swift

    public func formIntersection(_ x: RoaringBitmap)
  • Inplace version modifies x1, x1 == x2 is allowed

    Declaration

    Swift

    public static func &= (left: RoaringBitmap, right: RoaringBitmap)
  • Computes the size of the intersection between two bitmaps.

    Declaration

    Swift

    public func intersectionCount(_ x: RoaringBitmap) -> UInt64
  • Check whether two bitmaps intersect.

    Declaration

    Swift

    public func intersect(_ x: RoaringBitmap) -> Bool
  • Computes the Jaccard index between two bitmaps. (Also known as the Tanimoto distance, or the Jaccard similarity coefficient)

    The Jaccard index is undefined if both bitmaps are empty.

    Declaration

    Swift

    public func jaccardIndex(_ x: RoaringBitmap) -> Double
  • Computes the size of the union between two bitmaps.

    Declaration

    Swift

    public func unionCount(_ x: RoaringBitmap) -> UInt64
  • Computes the size of the difference (andnot) between two bitmaps.

    Declaration

    Swift

    public func subtractingCount(_ x: RoaringBitmap) -> UInt64
  • Computes the size of the symmetric difference (andnot) between two bitmaps.

    Declaration

    Swift

    public func symmetricDifferenceCount(_ x: RoaringBitmap) -> UInt64
  • Computes the union between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public func union(_ x: RoaringBitmap) -> RoaringBitmap
  • Computes the union between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public static func | (left: RoaringBitmap, right: RoaringBitmap) -> RoaringBitmap
  • Inplace version of union, modifies x1.

    Declaration

    Swift

    public func formUnion(_ x: RoaringBitmap)
  • Inplace version of union, modifies x1.

    Declaration

    Swift

    public static func |= (left: RoaringBitmap, right: RoaringBitmap)
  • Compute the union of ‘number’ bitmaps. See also unionManyHeap().

    Declaration

    Swift

    public func unionMany(_ xs: [RoaringBitmap]) -> RoaringBitmap
  • Compute the union of ‘number’ bitmaps using a heap. This can sometimes be faster than unionMany() which uses a naive algorithm.

    Declaration

    Swift

    public func unionManyHeap(_ xs: [RoaringBitmap]) -> RoaringBitmap
  • Computes the symmetric difference (xor) between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public func symmetricDifference(_ x: RoaringBitmap) -> RoaringBitmap
  • Computes the symmetric difference (xor) between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public static func ^ (left: RoaringBitmap, right: RoaringBitmap) -> RoaringBitmap
  • Inplace version of symmetricDifference(…), modifies x1. x1 != x2.

    Declaration

    Swift

    public func formSymmetricDifference(_ x: RoaringBitmap)
  • Inplace version of symmetricDifference(…), modifies x1. x1 != x2.

    Declaration

    Swift

    public static func ^= (left: RoaringBitmap, right: RoaringBitmap)
  • Compute the symmetric difference of n bitmaps.

    Declaration

    Swift

    public func symmetricDifferenceMany(_ xs: [RoaringBitmap]) -> RoaringBitmap
  • Computes the difference (andnot) between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public func subtracting(_ x: RoaringBitmap) -> RoaringBitmap
  • Computes the difference (andnot) between two bitmaps and returns new bitmap.

    Declaration

    Swift

    public static func - (left: RoaringBitmap, right: RoaringBitmap) -> RoaringBitmap
  • Inplace version of subtracting(…), modifies x1. x1 != x2.

    Declaration

    Swift

    public func subtract(_ x: RoaringBitmap)
  • Inplace version of subtracting(…), modifies x1. x1 != x2.

    Declaration

    Swift

    public static func -= (left: RoaringBitmap, right: RoaringBitmap)
  • Return true if the two bitmaps contain the same elements.

    Declaration

    Swift

    public func equals(_ x: RoaringBitmap) -> Bool
  • Return true if the two bitmaps contain the same elements.

    Declaration

    Swift

    public static func == (left: RoaringBitmap, right: RoaringBitmap) -> Bool
  • Return true if the two bitmaps DO NOT contain the same elements.

    Declaration

    Swift

    public static func != (left: RoaringBitmap, right: RoaringBitmap) -> Bool
  • Return true if all the elements of ra1 are also in ra2.

    Declaration

    Swift

    public func isSubset(of x: RoaringBitmap) -> Bool
  • Return true if all the elements of ra1 are also in ra2 and ra2 is strictly greater than ra1.

    Declaration

    Swift

    public func isStrictSubset(of x: RoaringBitmap) -> Bool
  • (For expert users who seek high performance.)

    Computes the union between two bitmaps and returns new bitmap.

    The lazy version defers some computations such as the maintenance of the cardinality counts. Thus you need to call repairAfterLazy() after executing lazy computations. It is safe to repeatedly call formLazyUnion() on the result. The bitsetconversion conversion is a flag which determines whether container-container operations force a bitset conversion.

    Declaration

    Swift

    public func lazyUnion(_ x: RoaringBitmap, bitsetconversion: Bool) -> RoaringBitmap
  • (For expert users who seek high performance.) Inplace version of lazyUnion(), modifies x1 The bitsetconversion conversion is a flag which determines whether container-container operations force a bitset conversion.

    Declaration

    Swift

    public func formLazyUnion(_ x: RoaringBitmap, bitsetconversion: Bool)
  • (For expert users who seek high performance.)

    Execute maintenance operations on a bitmap created from lazyUnion(…) or modified with formLazyUnion(…).

    Declaration

    Swift

    public func repairAfterLazy()
  • Computes the symmetric difference between two bitmaps and returns new bitmap. The caller is responsible for memory management.

    The lazy version defers some computations such as the maintenance of the cardinality counts. Thus you need to call repairAfterLazy() after executing lazy computations. It is safe to repeatedly call formLazySymmetricDifference(…) on the result.

    Declaration

    Swift

    public func lazySymmetricDifference(_ x: RoaringBitmap) -> RoaringBitmap
  • (For expert users who seek high performance.) Inplace version of lazySymmetricDifference(…), modifies x1. x1 != x2

    Declaration

    Swift

    public func formLazySymmetricDifference(_ x: RoaringBitmap)
  • compute the negation of the roaring bitmap within a specified interval: [rangeStart, rangeEnd). The number of negated values is rangeEnd - rangeStart. Areas outside the range are passed through unchanged.

    Declaration

    Swift

    public func flip(rangeStart: UInt64, rangeEnd: UInt64) -> RoaringBitmap
  • compute (in place) the negation of the roaring bitmap within a specified interval: [rangeStart, rangeEnd). The number of negated values is rangeEnd - rangeStart. Areas outside the range are passed through unchanged.

    Declaration

    Swift

    public func flipInplace(rangeStart: UInt64, rangeEnd: UInt64)
  • Undocumented

    Declaration

    Swift

    public func copy() -> RoaringBitmap
  • Add value to bitmap

    Declaration

    Swift

    public func add(_ value: UInt32)
  • Add values in format [UInt32], faster than repeatedly calling add(…)

    Declaration

    Swift

    public func addMany(values: [UInt32])
  • Add value x Returns true if a new value was added, false if the value was already existing.

    Declaration

    Swift

    public func addCheck(_ value: UInt32) -> Bool
  • Add all values in range [min, max]

    Declaration

    Swift

    public func addRangeClosed(min: UInt32, max: UInt32)
  • Add all values in range [min, max)

    Declaration

    Swift

    public func addRange(min: UInt64, max: UInt64)
  • Remove value x

    Declaration

    Swift

    public func remove(_ value: UInt32)
  • Remove all values in range [min, max]

    Declaration

    Swift

    public func removeRangeClosed(min: UInt32, max: UInt32)
  • Remove all values in range [min, max)

    Declaration

    Swift

    public func removeRange(min: UInt64, max: UInt64)
  • Remove value x Returns true if a new value was removed, false if the value was not existing.

    Declaration

    Swift

    public func removeCheck(_ value: UInt32) -> Bool
  • Empties the bitmap.

    Declaration

    Swift

    public func clear()
  • Get the cardinality of the bitmap (number of elements).

    Declaration

    Swift

    public var count: UInt64 { get }
  • Check if value x is present

    Declaration

    Swift

    public func contains(_ value: UInt32) -> Bool
  • Check whether a range of values from start (included) to end (excluded) is present

    Declaration

    Swift

    public func containsRange(start: UInt64, end: UInt64) -> Bool
  • Check whether the bitmap is empty

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Print the content of the bitmap.

    Declaration

    Swift

    public func print()
  • Describe the inner structure of the bitmap.

    Declaration

    Swift

    public func describe()
  • Convert the bitmap to an array.

    Declaration

    Swift

    public func toArray() -> [UInt32]
  • Remove run-length encoding even when it is more space efficient return whether a change was applied

    Declaration

    Swift

    public func removeRunCompression() -> Bool
  • convert array and bitmap containers to run containers when it is more

    • efficient;
    • also convert from run containers when more space efficient. Returns
    • true if the result has at least one run container.
    • Additional savings might be possible by calling shrinkToFit().

    Declaration

    Swift

    public func runOptimize() -> Bool
  • If needed, reallocate memory to shrink the memory usage. Returns the number of bytes saved.

    Declaration

    Swift

    public func shrink() -> size_t
  • write the bitmap to an output pointer, this output buffer should refer to at least SizeInBytes(…) allocated bytes.

    see portableSerialize if you want a format that’s compatible with Java and Go implementations

    this format has the benefit of being sometimes more space efficient than portableSerialize e.g., when the data is sparse.

    Returns how many bytes were written which should be SizeInBytes(…).

    Declaration

    Swift

    public func serialize(buffer: [Int8]) -> size_t
  • use with serialize(…)

    See

    see portableSerialize(…) if you want a format that’s
  • compatible with Java and Go implementations
  • Declaration

    Swift

    public static func deserialize(buffer: [Int8]) -> RoaringBitmap
  • How many bytes are required to serialize this bitmap (NOT compatible with Java and Go versions)

    Declaration

    Swift

    public func sizeInBytes() -> size_t
  • read a bitmap from a serialized version. This is meant to be compatible with the Java and Go versions. See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec In case of failure, a null pointer is returned. This function is unsafe in the sense that if there is no valid serialized bitmap at the pointer, then many bytes could be read, possibly causing a buffer overflow. For a safer approach, call portableDeserializeSafe(…).

    Declaration

    Swift

    public static func portableDeserialize(buffer: [Int8]) -> RoaringBitmap
  • read a bitmap from a serialized version in a safe manner (reading up to maxbytes). This is meant to be compatible with the Java and Go versions. See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec In case of failure, a nil pointer is returned.

    Declaration

    Swift

    public static func portableDeserializeSafe(buffer: [Int8], maxbytes: size_t) -> RoaringBitmap
  • Check how many bytes would be read (up to maxbytes) at this pointer if there is a bitmap, returns zero if there is no valid bitmap. This is meant to be compatible with the Java and Go versions. See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec

    Declaration

    Swift

    public static func portableDeserializeSize(buffer: [Int8], maxbytes: size_t) -> size_t
  • How many bytes are required to serialize this bitmap (meant to be compatible with Java and Go versions). See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec

    Declaration

    Swift

    public func portableSizeInBytes() -> size_t
  • write a bitmap to a char buffer. The output buffer should refer to at least portableSizeInBytes() bytes of allocated memory. This is meant to be compatible with the Java and Go versions. Returns how many bytes were written which should be portableSizeInBytes(). See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec

    Declaration

    Swift

    public func portableSerialize(buffer: [Int8]) -> size_t
    • If the size of the roaring bitmap is strictly greater than rank, then this function returns true and set the value to the the given rank. Otherwise, it returns false.

    Declaration

    Swift

    public func select(rank: UInt32, value: UInt32) -> Bool
  • Returns the number of integers that are smaller or equal to x.

    Declaration

    Swift

    public func rank(value: UInt32) -> UInt64
  • Returns the smallest value in the set. Returns UINT32_MAX if the set is empty.

    Declaration

    Swift

    public func min() -> UInt32
  • Returns the greatest value in the set. Returns 0 if the set is empty.

    Declaration

    Swift

    public func max() -> UInt32
  • (For advanced users.) Collect statistics about the bitmap, see roaring_statistics_t for a description of RoaringStatistics

    Declaration

    Swift

    public func statistics() -> RoaringStatistics
  • Creates a RoaringBitmapIterator.

    Declaration

    Swift

    public func makeIterator() -> RoaringBitmapIterator
  • code used to iterate through values in a roaring bitmap

    See more

    Declaration

    Swift

    public struct RoaringBitmapIterator : IteratorProtocol
  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public var hashValue: Int { get }