|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | /// A sorted collection of comparable elements; also known as a multiset.
|
10 |
| -/// `SortedBag` is like a `SortedSet` that allows multiple members that are equal to each other. |
| 10 | +/// `SortedBag` is like a `SortedSet` except it can contain multiple members that are equal to each other. |
11 | 11 | /// Lookup, insertion and removal of any element has logarithmic complexity.
|
12 | 12 | ///
|
13 | 13 | /// `SortedBag` stores duplicate elements in their entirety; it doesn't just count multiplicities.
|
14 | 14 | /// This is an important feature when equal elements can be distinguished by identity comparison or some other means.
|
| 15 | +/// (If you're OK with just counting duplicates, use a `Map` or a `Dictionary` with the multiplicity as the value.) |
15 | 16 | ///
|
16 | 17 | /// `SortedBag` is a struct with copy-on-write value semantics, like Swift's standard collection types.
|
17 |
| -/// It uses an in-memory b-tree for element storage, whose individual nodes may be shared with other ordered sets. |
18 |
| -/// Mutating a set whose storage is (partially or completely) shared requires copying of only O(log(`count`)) elements. |
19 |
| -/// (Thus, mutation of shared ordered sets may be cheaper than ordinary sets, which need to copy all elements.) |
| 18 | +/// It uses an in-memory b-tree for element storage, whose individual nodes may be shared with other sorted sets or bags. |
| 19 | +/// Mutating a bag whose storage is (partially or completely) shared requires copying of only O(log(`count`)) elements. |
| 20 | +/// (Thus, mutation of shared `SortedBag`s may be cheaper than ordinary `Set`s, which need to copy all elements.) |
20 | 21 | ///
|
21 |
| -/// Set operations on ordered sets (such as taking the union, intersection or difference) can take as little as |
| 22 | +/// Set operations on sorted bags (such as taking the union, intersection or difference) can take as little as |
22 | 23 | /// O(log(n)) time if the elements in the input bags aren't too interleaved.
|
| 24 | +/// |
| 25 | +/// - SeeAlso: `SortedSet` |
23 | 26 | public struct SortedBag<Element: Comparable>: SetAlgebra {
|
24 | 27 | internal typealias Tree = BTree<Element, Void>
|
25 | 28 |
|
|
0 commit comments