Fix typos

This commit is contained in:
Dimitris Apostolou committed 2024-02-04 20:35:42 +02:00
1 parent 427083e64d
commit ab744afc39
17 files changed
+99 -99

No files matched your search

@@ -199,7 +199,7 @@ extension _UnsafeMutableWrappedBuffer {
// Note: Array._copyContents traps when not given enough space, so we
// need to check if we have enough contiguous space available above.
//
// FIXME: Add suppport for segmented (a.k.a. piecewise contiguous)
// FIXME: Add support for segmented (a.k.a. piecewise contiguous)
// collections to the stdlib.
var (it, copied) = elements._copyContents(initializing: first)
if copied == first.count, let second = second {
@@ -874,7 +874,7 @@ extension _RawHashNode {
}
distance += c
}
// See if the target is hiding somwhere in our immediate items.
// See if the target is hiding somewhere in our immediate items.
distance &+= $0.itemCount
if distance >= 0 {
path.selectItem(at: _HashSlot(distance))
@@ -18,7 +18,7 @@ extension TreeSet: ExpressibleByArrayLiteral {
/// Do not call this initializer directly. It is used by the compiler when
/// you use an array literal. Instead, create a new persistent set using an
/// array literal as its value by enclosing a comma-separated list of values
/// in square brackets. You can use an array literal anywhere a peristent set
/// in square brackets. You can use an array literal anywhere a persistent set
/// is expected by the type context.
///
/// Like the standard `Set`, persistent sets do not preserve the order of
@@ -14,7 +14,7 @@ extension _HashTable {
/// table. This is a convenient tool for implementing linear probing.
///
/// Beyond merely providing bucket values, bucket iterators can also tell
/// you their current oposition within the hash table, and (for mutable hash
/// you their current opposition within the hash table, and (for mutable hash
/// tables) they allow you update the value of the currently visited bucket.
/// (This is useful when implementing simple insertions, for example.)
///
@@ -240,7 +240,7 @@ import _CollectionsUtilities
/// The hash table in an ordered set never needs to store larger indices than
/// the current size of the storage array, and `OrderedSet` makes use of this
/// observation to reduce the number of bits it uses to encode these integer
/// vaues. Additionally, the actual hashed elements are stored in a flat array
/// values. Additionally, the actual hashed elements are stored in a flat array
/// value rather than the hash table itself, so they aren't subject to the hash
/// table's strict maximum load factor. These two observations combine to
/// optimize the memory utilization of `OrderedSet`, sometimes making it even
@@ -34,7 +34,7 @@ extension BigString._Chunk: CustomStringConvertible {
func _succinctContents(maxLength c: Int) -> String {
/// 4+"short"-1
/// 0+"longer...tring"-1
/// 0+"longer...string"-1
let pc = String(prefixCount)._lpad(to: 3)
let sc = String(suffixCount)
@@ -20,7 +20,7 @@ public protocol RopeMetric<Element>: Sendable {
///
/// - Parameter offset: An integer offset from the start of `element` in this
/// metric, not exceeding `size(of: element.summary)`.
/// - Parameter element: An arbitary rope element.
/// - Parameter element: An arbitrary rope element.
/// - Returns: The index addressing the desired position in the input element.
func index(at offset: Int, in element: Element) -> Element.Index
}
@@ -11,7 +11,7 @@
// This contains `_BTree`'s general implementation of BidirectionalCollection.
// These operations are bounds in contrast to most other methods on _BTree as
// they are designed to be easily propogated to a higher-level data type.
// they are designed to be easily propagated to a higher-level data type.
// However, they still do not perform index validation
extension _BTree: BidirectionalCollection {
@@ -58,7 +58,7 @@ extension _BTree {
/// The depth at which the last instance of sequential unique nodes starting at the root was found.
///
/// In the following path where 'U' denotes a unique node, and 'S' denotes a shared node. The value
/// of this parameter would be '1' indicating the second level of the tre.
/// of this parameter would be '1' indicating the second level of the tree.
///
/// ┌─┐
/// │U├─┐
@@ -189,7 +189,7 @@ extension _BTree {
// Update the bottom-most node
var (node, result) = try self.updateNode(atDepth: path.depth - 1, body)
// Start the node above the bottom-most node, and propogate up the change
// Start the node above the bottom-most node, and propagate up the change
var depth = path.depth - 2
while depth >= 0 {
if depth > lastUniqueDepth {
@@ -258,7 +258,7 @@ extension _BTree {
/// - element: A new key-value element to insert.
/// - capacity: Capacity of new internal nodes created during insertion.
/// - Returns: The new root object which may equal in identity to the previous one.
/// - Warning: Doesn not check sortedness invariant
/// - Warning: Does not check sortedness invariant
/// - Complexity: O(`log n`). Ascends the tree once
@inlinable
internal mutating func insertElement(
@@ -272,7 +272,7 @@ extension _BTree {
handle.insertElement(element, withRightChild: nil, atSlot: slot)
}
// Start the node above the bottom-most node, and propogate up the change
// Start the node above the bottom-most node, and propagate up the change
var depth = path.depth - 2
while depth >= 0 {
let (newNode, _) = self.updateNode(atDepth: depth) { (handle, slot) in
@@ -12,14 +12,14 @@
extension _BTree {
/// Provides an interface for efficiently constructing a filled B-Tree from sorted data.
///
/// A builder supports duplicate keys, in which case they are inserted in the same order they are recieved.
/// A builder supports duplicate keys, in which case they are inserted in the same order they are received.
/// However, is the `deduplicating` parameter is passed as `true`, operations will silently drop
/// duplicates.
///
/// This type has a few advantages when constructing a B-Tree over other approaches such as manually
/// inserting each element or using a cursor:
///
/// This works by maintaing a list of saplings and a view of the node currently being modified. For example
/// This works by maintaining a list of saplings and a view of the node currently being modified. For example
/// the following tree:
///
/// ┌─┐
@@ -49,21 +49,21 @@ extension _BTree {
/// └─┘ └─┘
///
/// ┌─┐ ┌─┐
/// Seperators: │D│ │F│
/// Separators: │D│ │F│
/// └─┘ └─┘
///
/// While the diagrams above represent a binary-tree, the representation of a B-Tree in the builder is
/// directly analogous to this. By representing the state this way. Append operations can be efficiently
/// performed, and the tree can also be efficiently reconstructed.
///
/// Appending works by filling in a seedling, once a seedling is full, and an associated seperator has been
/// provided, the seedling-seperator pair can be appended to the stack.
/// Appending works by filling in a seedling, once a seedling is full, and an associated separator has been
/// provided, the seedling-separator pair can be appended to the stack.
@usableFromInline
internal struct Builder {
@usableFromInline
enum State {
/// The builder needs to add a seperator to the node
case addingSeperator
/// The builder needs to add a separator to the node
case addingSeparator
/// The builder needs to try to append to the seedling node.
case appendingToSeedling
@@ -73,7 +73,7 @@ extension _BTree {
internal var _saplings: [Node]
@usableFromInline
internal var _seperators: [Element]
internal var _separators: [Element]
@usableFromInline
internal var _seedling: Node?
@@ -153,7 +153,7 @@ extension _BTree {
"Capacity must be greater than one")
self._saplings = []
self._seperators = []
self._separators = []
self.state = .appendingToSeedling
self._seedling = Node(withCapacity: leafCapacity, isLeaf: true)
self.leafCapacity = leafCapacity
@@ -162,26 +162,26 @@ extension _BTree {
self.lastKey = nil
}
/// Pops a sapling and it's associated seperator
/// Pops a sapling and it's associated separator
@inlinable
@inline(__always)
internal mutating func popSapling()
-> (leftNode: Node, seperator: Element)? {
-> (leftNode: Node, separator: Element)? {
return _saplings.isEmpty ? nil : (
leftNode: _saplings.removeLast(),
seperator: _seperators.removeLast()
separator: _separators.removeLast()
)
}
/// Appends a sapling with an associated seperator
/// Appends a sapling with an associated separator
@inlinable
@inline(__always)
internal mutating func appendSapling(
_ sapling: __owned Node,
seperatedBy seperator: Element
separatedBy separator: Element
) {
_saplings.append(sapling)
_seperators.append(seperator)
_separators.append(separator)
}
/// Appends a sequence of sorted values to the tree
@@ -209,8 +209,8 @@ extension _BTree {
}
switch state {
case .addingSeperator:
completeSeedling(withSeperator: element)
case .addingSeparator:
completeSeedling(withSeparator: element)
state = .appendingToSeedling
case .appendingToSeedling:
@@ -220,7 +220,7 @@ extension _BTree {
}
if _slowPath(isFull) {
state = .addingSeperator
state = .addingSeparator
}
}
}
@@ -231,7 +231,7 @@ extension _BTree {
/// further operate on.
@inlinable
internal mutating func completeSeedling(
withSeperator newSeperator: __owned Element
withSeparator newSeparator: __owned Element
) {
var sapling = Node(withCapacity: leafCapacity, isLeaf: true)
swap(&sapling, &self.seedling)
@@ -242,7 +242,7 @@ extension _BTree {
// bits
// - The stack has saplings of decreasing depth.
// - Saplings on the stack are completely filled except for their roots.
if case (var previousSapling, let seperator)? = self.popSapling() {
if case (var previousSapling, let separator)? = self.popSapling() {
let saplingDepth = sapling.storage.header.depth
let previousSaplingDepth = previousSapling.storage.header.depth
let previousSaplingIsFull = previousSapling.read({ $0.isFull })
@@ -260,7 +260,7 @@ extension _BTree {
// │ │
// previousSapling sapling
//
// We then use the seperator (B) to transform this into a subtree of a
// We then use the separator (B) to transform this into a subtree of a
// depth increase:
// ┌───┐
// │ B │ ◄─── sapling
@@ -273,12 +273,12 @@ extension _BTree {
// depth of our B-Tree increases
sapling = _Node(
leftChild: previousSapling,
seperator: seperator,
separator: separator,
rightChild: sapling,
capacity: internalCapacity
)
} else if saplingDepth + 1 == previousSaplingDepth && !previousSaplingIsFull {
// This is when we can append the node with the seperator:
// This is when we can append the node with the separator:
//
// ┌───┐
// │ B │ ◄─ previousSapling
@@ -288,7 +288,7 @@ extension _BTree {
// │ A │ │ C │ │ E │ ◄─ sapling
// └───┘ └───┘ └───┘
//
// We then use the seperator (D) to append this to previousSapling.
// We then use the separator (D) to append this to previousSapling.
// ┌────┬───┐
// │ B │ D │ ◄─ sapling
// ┌┴────┼───┴┐
@@ -297,7 +297,7 @@ extension _BTree {
// │ A │ │ C │ │ E │
// └───┘ └───┘ └───┘
previousSapling.update {
$0.appendElement(seperator, withRightChild: sapling)
$0.appendElement(separator, withRightChild: sapling)
}
sapling = previousSapling
} else {
@@ -327,11 +327,11 @@ extension _BTree {
// └───┘ └───┘ └───┘ └───┘ └───┘ └───┘
//
// We can string them together using the previous cases.
self.appendSapling(previousSapling, seperatedBy: seperator)
self.appendSapling(previousSapling, separatedBy: separator)
}
}
self.appendSapling(sapling, seperatedBy: newSeperator)
self.appendSapling(sapling, separatedBy: newSeparator)
}
/// Finishes building a tree.
@@ -344,11 +344,11 @@ extension _BTree {
var root: Node = seedling
_seedling = nil
while case (var sapling, let seperator)? = self.popSapling() {
while case (var sapling, let separator)? = self.popSapling() {
root = _Node.join(
&sapling,
with: &root,
seperatedBy: seperator,
separatedBy: separator,
capacity: internalCapacity
)
}
+4 -4
View File
@@ -104,7 +104,7 @@ internal struct _BTree<Key: Comparable, Value> {
/// Creates an empty B-Tree which creates node with specified capacities
/// - Parameters:
/// - leafCapacity: The capacity of the leaf nodes. This is the initial buffer used to allocate.
/// - internalCapacity: The capacity of the internal nodes. Generally prefered to be less than
/// - internalCapacity: The capacity of the internal nodes. Generally preferred to be less than
/// `leafCapacity`.
@inlinable
@inline(__always)
@@ -115,7 +115,7 @@ internal struct _BTree<Key: Comparable, Value> {
)
}
/// Creates a B-Tree rooted at a specific nodey
/// Creates a B-Tree rooted at a specific node
/// - Parameters:
/// - root: The root node.
/// - internalCapacity: The key capacity of new internal nodes.
@@ -231,7 +231,7 @@ extension _BTree {
}
}
// MARK: Removal Opertations
// MARK: Removal Operations
extension _BTree {
/// Removes the element of a tree at a given offset.
///
@@ -561,7 +561,7 @@ extension _BTree {
}
// MARK: Immutable Operatoins
// MARK: Immutable Operations
extension _BTree {
@inlinable
@inline(__always)
@@ -20,7 +20,7 @@ extension _Node {
self.rightChild = rightChild
}
/// The former median element which should be propogated upward.
/// The former median element which should be propagated upward.
@usableFromInline
internal let element: Element
@@ -42,7 +42,7 @@ extension _Node {
) -> _Node {
return _Node(
leftChild: leftChild,
seperator: element,
separator: element,
rightChild: rightChild,
capacity: capacity
)
@@ -139,7 +139,7 @@ extension _Node {
/// storage class is indeed unique. Generally this is the wrong function to call, and should only be used
/// when the callee has created and is guaranteed to be the only owner during the execution of the
/// update callback, _and_ it has been identified that ``_Node.update(_:)`` or other alternatives
/// result in noticable slow-down.
/// result in noticeable slow-down.
///
/// - Parameter body: A closure with a handle which allows interacting with the node
/// - Returns: The value the closure body returns, if any.
@@ -294,7 +294,7 @@ extension _Node.UnsafeHandle {
/// Inserts a splinter, attaching the children appropriately.
///
/// This only updates the count properties by one (for the seperator). If the splinter's right child contains a
/// This only updates the count properties by one (for the separator). If the splinter's right child contains a
/// different amount of elements than previously existed in the tree, explicitly handle those count changes.
/// See ``_Node.UnsafeHandle._adjustSubtreeCount(afterSplittingTo:)`` to
/// potentially ease this task.
@@ -361,20 +361,20 @@ extension _Node.UnsafeHandle {
/// Additionally, this **consumes** the source node which will marked to be deallocated.
///
/// - Parameters:
/// - rightNode: A consumed node with keys greater than or equal to the seperator.
/// - seperatedBy: A seperator greater than or equal to all keys in the current node.
/// - rightNode: A consumed node with keys greater than or equal to the separator.
/// - separatedBy: A separator greater than or equal to all keys in the current node.
/// - Returns: A splinter if the node could not contain both elements.
@inlinable
internal func concatenateWith(
node rightNode: inout _Node,
seperatedBy seperator: __owned _Node.Element
separatedBy separator: __owned _Node.Element
) -> _Node.Splinter? {
assertMutable()
let seperator: _Node.Element? = rightNode.update { rightHandle in
let separator: _Node.Element? = rightNode.update { rightHandle in
assert(self.elementCount + rightHandle.elementCount <= 2 * self.capacity,
"Parameters are too large to concatenate.")
assert(self.depth == rightHandle.depth,
"Cannot concatenate nodes of varying depths. See appendNode(_:seperatedBy:)")
"Cannot concatenate nodes of varying depths. See appendNode(_:separatedBy:)")
let totalElementCount = self.elementCount + rightHandle.elementCount + 1
@@ -383,17 +383,17 @@ extension _Node.UnsafeHandle {
// A splinter needs to occur
// Split evenly (right biased).
let seperatorSlot = totalElementCount / 2
let separatorSlot = totalElementCount / 2
// Identify who needs to splinter
if seperatorSlot == self.elementCount {
// The nice case when the seperator is the splinter
return seperator
} else if seperatorSlot < self.elementCount {
if separatorSlot == self.elementCount {
// The nice case when the separator is the splinter
return separator
} else if separatorSlot < self.elementCount {
// Move elements from the left node to the right node
let splinterSeperator = self.moveElement(atSlot: seperatorSlot)
let splinterSeparator = self.moveElement(atSlot: separatorSlot)
let shiftedElementCount = self.elementCount - seperatorSlot - 1
let shiftedElementCount = self.elementCount - separatorSlot - 1
rightHandle.moveInitializeElements(
count: rightHandle.elementCount,
@@ -404,12 +404,12 @@ extension _Node.UnsafeHandle {
rightHandle.initializeElement(
atSlot: shiftedElementCount,
to: seperator
to: separator
)
self.moveInitializeElements(
count: shiftedElementCount,
fromSlot: seperatorSlot + 1,
fromSlot: separatorSlot + 1,
toSlot: 0,
of: rightHandle
)
@@ -424,66 +424,66 @@ extension _Node.UnsafeHandle {
self.moveInitializeChildren(
count: shiftedElementCount + 1,
fromSlot: seperatorSlot + 1,
fromSlot: separatorSlot + 1,
toSlot: 0,
of: rightHandle
)
}
// TODO: adjust counts
self.elementCount = seperatorSlot
rightHandle.elementCount = totalElementCount - seperatorSlot - 1
self.elementCount = separatorSlot
rightHandle.elementCount = totalElementCount - separatorSlot - 1
self._adjustSubtreeCount(afterSplittingTo: rightHandle)
return splinterSeperator
return splinterSeparator
} else {
// seperatorSlot > self.elementCount
// separatorSlot > self.elementCount
// Move elements from the right node to the left node
let seperatorSlotInRightHandle = seperatorSlot - self.elementCount - 1
let splinterSeperator =
rightHandle.moveElement(atSlot: seperatorSlotInRightHandle)
let separatorSlotInRightHandle = separatorSlot - self.elementCount - 1
let splinterSeparator =
rightHandle.moveElement(atSlot: separatorSlotInRightHandle)
self.initializeElement(
atSlot: self.elementCount,
to: seperator
to: separator
)
rightHandle.moveInitializeElements(
count: seperatorSlotInRightHandle,
count: separatorSlotInRightHandle,
fromSlot: 0,
toSlot: self.elementCount + 1,
of: self
)
rightHandle.moveInitializeElements(
count: rightHandle.elementCount - (seperatorSlotInRightHandle + 1),
fromSlot: seperatorSlotInRightHandle + 1,
count: rightHandle.elementCount - (separatorSlotInRightHandle + 1),
fromSlot: separatorSlotInRightHandle + 1,
toSlot: 0,
of: rightHandle
)
if !self.isLeaf {
rightHandle.moveInitializeChildren(
count: seperatorSlotInRightHandle + 1,
count: separatorSlotInRightHandle + 1,
fromSlot: 0,
toSlot: self.childCount,
of: self
)
}
self.elementCount = seperatorSlot
rightHandle.elementCount = totalElementCount - seperatorSlot - 1
self.elementCount = separatorSlot
rightHandle.elementCount = totalElementCount - separatorSlot - 1
self._adjustSubtreeCount(afterSplittingTo: rightHandle)
return splinterSeperator
return splinterSeparator
}
} else {
// A simple merge can be performed
self.initializeElement(
atSlot: self.elementCount,
to: seperator
to: separator
)
rightHandle.moveInitializeElements(
@@ -513,8 +513,8 @@ extension _Node.UnsafeHandle {
}
// Check if it splintered
if let seperator = seperator {
return _Node.Splinter(element: seperator, rightChild: rightNode)
if let separator = separator {
return _Node.Splinter(element: separator, rightChild: rightNode)
} else {
return nil
}
+11 -11
View File
@@ -71,11 +71,11 @@ internal struct _Node<Key: Comparable, Value> {
self._storage = storage
}
/// Creates a new node from a left, right, and seperator.
/// Creates a new node from a left, right, and separator.
@inlinable
internal init(
leftChild: __owned _Node,
seperator: __owned Element,
separator: __owned Element,
rightChild: __owned _Node,
capacity: Int
) {
@@ -86,9 +86,9 @@ internal struct _Node<Key: Comparable, Value> {
self.init(withCapacity: capacity, isLeaf: false)
self.storage.updateGuaranteedUnique { handle in
handle.keys.initialize(to: seperator.key)
handle.keys.initialize(to: separator.key)
if _Node.hasValues {
handle.values.unsafelyUnwrapped.initialize(to: seperator.value)
handle.values.unsafelyUnwrapped.initialize(to: separator.value)
}
handle.children.unsafelyUnwrapped.initialize(to: leftChild)
@@ -198,21 +198,21 @@ extension _Node {
/// Joins the current node with another node of potentially differing depths.
///
/// If you know that your nodes are the same depth, then use
/// ``_Node.UnsafeHandle.concatenateWith(node:seperatedBy:)``.
/// ``_Node.UnsafeHandle.concatenateWith(node:separatedBy:)``.
///
/// - Parameters:
/// - leftNode:A well-formed node with elements less than or equal to `seperator`. This
/// - leftNode:A well-formed node with elements less than or equal to `separator`. This
/// node is **consumed and invalided** when this method is called.
/// - rightNode: A well-formed node with elements greater than or equal to `seperator`. This
/// - rightNode: A well-formed node with elements greater than or equal to `separator`. This
/// node is **consumed and invalided** when this method is called.
/// - seperator: An element greater than or equal to all elements in the current node.
/// - separator: An element greater than or equal to all elements in the current node.
/// - Returns: A new node containing both the right and left node combined. This may or may not be
/// referentially identical to one of the old nodes.
@inlinable
internal static func join(
_ leftNode: inout _Node,
with rightNode: inout _Node,
seperatedBy seperator: __owned _Node.Element,
separatedBy separator: __owned _Node.Element,
capacity: Int
) -> _Node {
let leftNodeDepth = leftNode.storage.header.depth
@@ -226,7 +226,7 @@ extension _Node {
) -> _Node.Splinter? {
if depth == 0 {
let splinter = leftNode.update {
$0.concatenateWith(node: &node, seperatedBy: seperator)
$0.concatenateWith(node: &node, separatedBy: separator)
}
node = leftNode
return splinter
@@ -252,7 +252,7 @@ extension _Node {
if depth == 0 {
// Graft at the current node
return node.concatenateWith(node: &rightNode, seperatedBy: seperator)
return node.concatenateWith(node: &rightNode, separatedBy: separator)
} else {
let endSlot = node.childCount - 1
let splinter = node[childAt: endSlot].update {
+1 -1
View File
@@ -968,7 +968,7 @@ class TestBigString: CollectionTestCase {
let b1: BigString = "Foobar"
var s1 = b1.suffix(3)
expectEqual(s1, "bar")
s1.insert("\u{308}", at: s1.startIndex) // Combining diaresis
s1.insert("\u{308}", at: s1.startIndex) // Combining diaeresis
expectEqual(s1.base, "Foöbar")
expectEqual(s1, "öbar")
@@ -16,7 +16,7 @@ import _CollectionsTestSupport
func expectNodeJoin(
capacity: Int,
tree1: NodeTemplate,
seperator: Int,
separator: Int,
tree2: NodeTemplate,
toEqual refTree: NodeTemplate
) {
@@ -26,7 +26,7 @@ func expectNodeJoin(
let newTree = _Node.join(
&tree1,
with: &tree2,
seperatedBy: (seperator, -seperator),
separatedBy: (separator, -separator),
capacity: capacity
)
@@ -42,7 +42,7 @@ final class NodeJoinTests: CollectionTestCase {
tree1: tree {
0
},
seperator: 1,
separator: 1,
tree2: tree {
2; 3; 4
},
@@ -54,7 +54,7 @@ final class NodeJoinTests: CollectionTestCase {
tree1: tree {
0
},
seperator: 1,
separator: 1,
tree2: tree {
2; 3; 4; 5
},
@@ -76,7 +76,7 @@ final class NodeJoinTests: CollectionTestCase {
2
tree { 3 }
},
seperator: 4,
separator: 4,
tree2: tree {
tree { 5 }
6