Files
swift-collections/Sources/PersistentCollections/_Common.swift
T
Karoy Lorentey 14f90620c8 [PersistentCollections] Introduce _Bucket, _Bitmap, _HashPath, and _HashValue
These provide nicer tools for slicing up hash values and dealing with node bitmaps.

_Bucket is a logical entry in the hash table inside a node.
_Bitmap is a set of bucket values, represented by a bitset.
_HashPath facilitates slicing up a hash value into a series of bucket values.
_HashValue represents a hash value.

This is still just mostly superficial refactoring, with little to no functional changes.
2022-09-09 00:47:10 -07:00

61 lines
1.5 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2019 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
internal func _computeHash<T: Hashable>(_ value: T) -> Int {
value.hashValue
}
@inline(__always)
internal var _bitPartitionSize: Int { 5 }
@inline(__always)
internal var _bitPartitionMask: Int { (1 << _bitPartitionSize) - 1 }
@inline(__always)
internal var _hashCodeLength: Int { Int.bitWidth }
@inline(__always)
internal var _maxDepth: Int {
(_hashCodeLength + _bitPartitionSize - 1) / _bitPartitionSize
}
// NEW
@inlinable
@inline(__always)
internal func _rangeInsert<T>(
_ element: T,
at index: Int,
into baseAddress: UnsafeMutablePointer<T>,
count: Int
) {
let src = baseAddress.advanced(by: index)
let dst = src.successor()
dst.moveInitialize(from: src, count: count - index)
src.initialize(to: element)
}
// NEW
@inlinable
@inline(__always)
internal func _rangeRemove<T>(
at index: Int,
from baseAddress: UnsafeMutablePointer<T>,
count: Int
) {
let src = baseAddress.advanced(by: index + 1)
let dst = src.predecessor()
dst.deinitialize(count: 1)
dst.moveInitialize(from: src, count: count - index - 1)
}