Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent collections updates (part 5) #179

Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
2e523b1
[PersistentCollections] Reverse ordering of items in node storage
lorentey Sep 16, 2022
3e38184
[PersistentCollections] Optimize _Node.==
lorentey Sep 16, 2022
edaadc9
[PersistentCollections] _Level: Store the shift amount in an UInt8
lorentey Sep 16, 2022
6dd0211
[PersistentCollections] Flesh out _RawNode, add _UnmanagedNode
lorentey Sep 16, 2022
547ac90
[PersistentCollections] Rework basic node properties
lorentey Sep 16, 2022
02133f1
[PersistentCollections] Implement path-based indices
lorentey Sep 16, 2022
16393ea
[PersistentCollections] Allow dumping hash trees in iteration order
lorentey Sep 16, 2022
bf3617e
[PersistentCollections] Work on testing a bit; add fixtures
lorentey Sep 16, 2022
0fe7f08
[PersistentCollections] offset → slot
lorentey Sep 16, 2022
52e3ea6
[test] LifetimeTracked: Implement high-fidelity hash forwarding
lorentey Sep 16, 2022
6cf128e
[PersistentCollections] Internal doc updates
lorentey Sep 16, 2022
1324c4e
[OrderedDictionary] Implement index invalidation
lorentey Sep 16, 2022
1661bd4
[PersistentDictionary] Implement in-place mutations for defaulted sub…
lorentey Sep 16, 2022
3b7d241
[PersistentDictionary] Add some docs
lorentey Sep 16, 2022
57deed5
[PersistentDictionary] Implement in-place mutations
lorentey Sep 17, 2022
2321b34
[PersistentCollections] Fix node sizing logic
lorentey Sep 17, 2022
5240bf6
[PersistentCollections] Reduce _Bucket’s storage size
lorentey Sep 18, 2022
d45f264
[PersistentDictionary] Fix index(forKey:) performance
lorentey Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 25 additions & 9 deletions Sources/PersistentCollections/Node/_Level.swift
Expand Up @@ -13,11 +13,17 @@
@frozen
internal struct _Level {
@usableFromInline
internal var shift: UInt
internal var _shift: UInt8
msteindorfer marked this conversation as resolved.
Show resolved Hide resolved

@inlinable @inline(__always)
init(_shift: UInt8) {
self._shift = _shift
}

@inlinable @inline(__always)
init(shift: UInt) {
self.shift = shift
assert(shift <= UInt8.max)
self._shift = UInt8(truncatingIfNeeded: shift)
}
}

Expand All @@ -28,8 +34,8 @@ extension _Level {
}

@inlinable @inline(__always)
internal static var _step: UInt {
UInt(bitPattern: _Bitmap.bitWidth)
internal static var _step: UInt8 {
UInt8(truncatingIfNeeded: _Bitmap.bitWidth)
}

@inlinable @inline(__always)
Expand All @@ -38,27 +44,37 @@ extension _Level {
}

@inlinable @inline(__always)
internal var isAtRoot: Bool { shift == 0 }
internal var shift: UInt { UInt(truncatingIfNeeded: _shift) }

@inlinable @inline(__always)
internal var isAtRoot: Bool { _shift == 0 }

@inlinable @inline(__always)
internal var isAtBottom: Bool { shift >= UInt.bitWidth }
internal var isAtBottom: Bool { _shift >= UInt.bitWidth }

@inlinable @inline(__always)
internal func descend() -> _Level {
// FIXME: Consider returning nil when we run out of bits
_Level(shift: shift &+ Self._step)
_Level(_shift: _shift &+ Self._step)
}

@inlinable @inline(__always)
internal func ascend() -> _Level {
assert(!isAtRoot)
return _Level(shift: shift &+ Self._step)
return _Level(_shift: _shift &- Self._step)
}
}

extension _Level: Equatable {
@inlinable @inline(__always)
internal static func ==(left: Self, right: Self) -> Bool {
left.shift == right.shift
left._shift == right._shift
}
}

extension _Level: Comparable {
@inlinable @inline(__always)
internal static func <(left: Self, right: Self) -> Bool {
left._shift < right._shift
}
}