Contents

RangeSet

A set of values of any comparable type, represented by ranges.

Declaration

struct RangeSet<Bound> where Bound : Comparable

Overview

You can use a range set to efficiently represent a set of Comparable values that spans any number of discontiguous ranges. Range sets are commonly used to represent multiple subranges of a collection, by storing ranges of a collection’s index type.

In this example, negativeSubranges is a range set representing the locations of all the negative values in numbers:

var numbers = [10, 12, -5, 14, -3, -9, 15]
let negativeSubranges = numbers.indices(where: { $0 < 0 })
// numbers[negativeSubranges].count == 3

numbers.moveSubranges(negativeSubranges, to: 0)
// numbers == [-5, -3, -9, 10, 12, 14, 15]

Topics

Structures

Initializers

Instance Properties

Instance Methods

Default Implementations

See Also

Ranges