9
9
// be a multiple of Element.bitWidth.
10
10
11
11
/// The containing integer.
12
- @usableFromInline
13
- var word : Wrapped
14
- /// The sub-word to be treated as the first element.
15
- @usableFromInline
16
- let initialBitRange : EmbeddedIteratorDirection
12
+ public var container : Wrapped
13
+ /// Which sub-word is to be treated as the first element.
14
+ public let endianness : EmbeddedIteratorDirection
17
15
18
16
/// Creates a collection vending elements of the given type embedded in
19
17
/// the given value,
42
40
within container: Wrapped = 0 ,
43
41
iteratingFrom bitRange: EmbeddedIteratorDirection
44
42
) {
45
- word = container
46
- initialBitRange = bitRange
43
+ self . container = container
44
+ endianness = bitRange
47
45
}
48
46
49
47
/// Creates a collection initially vending the maximum amount copies of
@@ -121,8 +119,8 @@ extension EmbeddedIntegerCollection: CustomStringConvertible {
121
119
extension EmbeddedIntegerCollection : CustomDebugStringConvertible {
122
120
public var debugDescription : String {
123
121
var result = String ( describing: Self . self)
124
- let hexValue = String ( word , radix: 16 , uppercase: true )
125
- switch initialBitRange {
122
+ let hexValue = String ( container , radix: 16 , uppercase: true )
123
+ switch endianness {
126
124
case . mostSignificantFirst:
127
125
print ( " (* " , hexValue, " ) " , separator: " " , terminator: " " , to: & result)
128
126
case . leastSignificantFirst:
@@ -159,7 +157,7 @@ extension EmbeddedIntegerCollection: RandomAccessCollection, MutableCollection {
159
157
160
158
@inlinable
161
159
public var startIndex : Index {
162
- switch initialBitRange {
160
+ switch endianness {
163
161
case . mostSignificantFirst:
164
162
Element . bitWidth - Wrapped. bitWidth
165
163
case . leastSignificantFirst:
@@ -168,7 +166,7 @@ extension EmbeddedIntegerCollection: RandomAccessCollection, MutableCollection {
168
166
}
169
167
@inlinable
170
168
public var endIndex : Index {
171
- switch initialBitRange {
169
+ switch endianness {
172
170
case . mostSignificantFirst:
173
171
Element . bitWidth
174
172
case . leastSignificantFirst:
@@ -178,17 +176,17 @@ extension EmbeddedIntegerCollection: RandomAccessCollection, MutableCollection {
178
176
179
177
public subscript( position: Index ) -> Element {
180
178
get {
181
- return . init( truncatingIfNeeded: word >> abs ( position) )
179
+ return . init( truncatingIfNeeded: container >> abs ( position) )
182
180
}
183
181
set {
184
182
let flipMask = self [ position] ^ newValue
185
- word ^= Wrapped ( flipMask) << abs ( position)
183
+ container ^= Wrapped ( flipMask) << abs ( position)
186
184
}
187
185
}
188
186
189
187
public mutating func swapAt( _ i: Int , _ j: Int ) {
190
188
let flipMask = Wrapped ( self [ i] ^ self [ j] )
191
- word ^= flipMask << abs ( i) | flipMask << abs ( j)
189
+ container ^= flipMask << abs ( i) | flipMask << abs ( j)
192
190
}
193
191
194
192
@inlinable
@@ -239,25 +237,25 @@ extension EmbeddedIntegerCollection: RandomAccessCollection, MutableCollection {
239
237
} )
240
238
else { return nil }
241
239
242
- assert ( copy. word == word ) // Check against accidental mutation
240
+ assert ( copy. container == container ) // Check against accidental mutation
243
241
return result
244
242
}
245
243
public mutating func withContiguousMutableStorageIfAvailable< R> (
246
244
_ body: ( inout UnsafeMutableBufferPointer < Element > ) throws -> R
247
245
) rethrows -> R ? {
248
246
guard Element . self is UInt8 . Type else { return nil }
249
- guard word is _ExpressibleByBuiltinIntegerLiteral else { return nil }
247
+ guard container is _ExpressibleByBuiltinIntegerLiteral else { return nil }
250
248
251
249
var storage =
252
- switch initialBitRange {
250
+ switch endianness {
253
251
case . mostSignificantFirst:
254
- word . bigEndian
252
+ container . bigEndian
255
253
case . leastSignificantFirst:
256
- word . littleEndian
254
+ container . littleEndian
257
255
}
258
256
defer {
259
- word =
260
- switch initialBitRange {
257
+ container =
258
+ switch endianness {
261
259
case . mostSignificantFirst:
262
260
Wrapped ( bigEndian: storage)
263
261
case . leastSignificantFirst:
@@ -440,8 +438,8 @@ extension EmbeddedIntegerCollection {
440
438
// Fill up the wrapping word from the most-significant element down.
441
439
var remainingElements = count
442
440
while remainingElements > 0 , let nextEmbeddedElement = iterator. next ( ) {
443
- word <<= Element . bitWidth
444
- word |= Wrapped ( nextEmbeddedElement)
441
+ container <<= Element . bitWidth
442
+ container |= Wrapped ( nextEmbeddedElement)
445
443
remainingElements -= 1
446
444
}
447
445
guard remainingElements == 0 else { return nil }
0 commit comments