---
title: RangeSet
framework: swift
role: symbol
role_heading: Structure
path: swift/rangeset
---

# RangeSet

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

## Declaration

```swift
struct RangeSet<Bound> where Bound : Comparable
```

## Overview

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

- [RangeSet.Ranges](swift/rangeset/ranges-swift.struct.md)

### Initializers

- [init()](swift/rangeset/init().md)
- [init(_:)](swift/rangeset/init(_:)-230uy.md)
- [init(_:)](swift/rangeset/init(_:)-42v9u.md)
- [init(_:)](swift/rangeset/init(_:)-9x0yj.md)
- [init(_:within:)](swift/rangeset/init(_:within:).md)

### Instance Properties

- [isEmpty](swift/rangeset/isempty.md)
- [ranges](swift/rangeset/ranges-swift.property.md)

### Instance Methods

- [contains(_:)](swift/rangeset/contains(_:).md)
- [formIntersection(_:)](swift/rangeset/formintersection(_:).md)
- [formSymmetricDifference(_:)](swift/rangeset/formsymmetricdifference(_:).md)
- [formUnion(_:)](swift/rangeset/formunion(_:).md)
- [insert(_:within:)](swift/rangeset/insert(_:within:).md)
- [insert(contentsOf:)](swift/rangeset/insert(contentsof:).md)
- [intersection(_:)](swift/rangeset/intersection(_:).md)
- [isDisjoint(_:)](swift/rangeset/isdisjoint(_:).md)
- [isStrictSubset(of:)](swift/rangeset/isstrictsubset(of:).md)
- [isStrictSuperset(of:)](swift/rangeset/isstrictsuperset(of:).md)
- [isSubset(of:)](swift/rangeset/issubset(of:).md)
- [isSuperset(of:)](swift/rangeset/issuperset(of:).md)
- [isValid(within:)](swift/rangeset/isvalid(within:)-38qb9.md)
- [isValid(within:)](swift/rangeset/isvalid(within:)-6u17e.md)
- [remove(_:within:)](swift/rangeset/remove(_:within:).md)
- [remove(contentsOf:)](swift/rangeset/remove(contentsof:).md)
- [subtract(_:)](swift/rangeset/subtract(_:).md)
- [subtracting(_:)](swift/rangeset/subtracting(_:).md)
- [symmetricDifference(_:)](swift/rangeset/symmetricdifference(_:).md)
- [union(_:)](swift/rangeset/union(_:).md)

### Default Implementations

- [CustomStringConvertible Implementations](swift/rangeset/customstringconvertible-implementations.md)
- [Equatable Implementations](swift/rangeset/equatable-implementations.md)
- [Hashable Implementations](swift/rangeset/hashable-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Ranges

- [..<(_:_:)](swift/comparable/'.._(_:_:).md)
- [Range](swift/range.md)
- [...(_:_:)](swift/comparable/'...(_:_:).md)
- [ClosedRange](swift/closedrange.md)
