mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
Follow the Standard Library coding style:
- Hard 80 character line limit
- Use two spaces as the indentation unit
- Overlong lines broken up by adding line breaks at the following places
1. After opening delimiters & before closing delimiters
2. Between each item in a list
3. Extracting subexpressions etc as needed
48 lines
1.2 KiB
Swift
48 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2021-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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
final class CollidableInt:
|
|
CustomStringConvertible, CustomDebugStringConvertible, Equatable, Hashable
|
|
{
|
|
let value: Int
|
|
let hashValue: Int
|
|
|
|
init(_ value: Int) {
|
|
self.value = value
|
|
self.hashValue = value
|
|
}
|
|
|
|
init(_ value: Int, _ hashValue: Int) {
|
|
self.value = value
|
|
self.hashValue = hashValue
|
|
}
|
|
|
|
var description: String {
|
|
return "\(value)"
|
|
}
|
|
|
|
var debugDescription: String {
|
|
return "\(value) [hash = \(hashValue)]"
|
|
}
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(hashValue)
|
|
}
|
|
|
|
static func == (lhs: CollidableInt, rhs: CollidableInt) -> Bool {
|
|
if lhs.value == rhs.value {
|
|
precondition(lhs.hashValue == rhs.hashValue)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|