This commit is contained in:
Ali
2021-09-03 00:45:22 +04:00
parent 8aefa19d31
commit 1fe0d4a75b
53 changed files with 489 additions and 566 deletions

View File

@@ -41,7 +41,8 @@ public struct ValueBoxKey: Equatable, Hashable, CustomStringConvertible, Compara
public func setData(_ offset: Int, value: Data) {
assert(offset >= 0 && offset + value.count <= self.length)
let valueLength = value.count
value.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
value.withUnsafeBytes { rawBytes -> Void in
let bytes = rawBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
memcpy(self.memory + offset, bytes, valueLength)
}
}
@@ -222,14 +223,9 @@ public struct ValueBoxKey: Equatable, Hashable, CustomStringConvertible, Compara
assert(range.lowerBound >= 0 && range.upperBound <= self.length)
return String(data: Data(bytes: self.memory.advanced(by: range.lowerBound), count: range.count), encoding: .utf8)
}
public var hashValue: Int {
var hash = 37
let bytes = self.memory.assumingMemoryBound(to: Int8.self)
for i in 0 ..< self.length {
hash = (hash &* 54059) ^ (Int(bytes[i]) &* 76963)
}
return hash
public func hash(into hasher: inout Hasher) {
hasher.combine(bytes: UnsafeRawBufferPointer(start: self.memory, count: self.length))
}
public static func ==(lhs: ValueBoxKey, rhs: ValueBoxKey) -> Bool {