swift - Swift 如何哈希字符串?

标签 swift string hashable

我正在查看 String ( https://github.com/apple/swift/blob/master/stdlib/public/core/String.swift ) 的 Swift 实现

String实现了Hashable协议(protocol),也就是说它必须提供一个hashValue。但是,上面链接的 String 实现中没有提供任何内容。我在哪里可以找到这个?我假设 String 从某处继承了它。

最佳答案

引用Swift String - Relationships提到的内容,你完全正确:

String implements the Hashable protocol...

您在问题中提供的文件的链接中看不到符合 Hashable 协议(protocol)的实现的原因是:

'String : Hashable' 一致性已移至单独的文件。你可以在这里找到它: https://github.com/apple/swift/blob/master/stdlib/public/core/StringHashable.swift ;请注意,该文件是 StringHashable.swift,但不是 String.swift

您还可以在此处找到此更改的提交: https://github.com/apple/swift/pull/4612/commits

关于swift - Swift 如何哈希字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878471/

相关文章:

c# - 如何返回以特定字符开头和结尾的所有单词?

Python——搜索子串全词)

swift - swift协议(protocol)Hashable中hashValue的性能考虑

swift - Set 如何确保 Swift 中的等同性?

c++ - 如何在 C++ 中将文件中的段落作为单个字符串读取

python - 使用联合将字典添加到 `set()`

ios - 单元格高度 : Thread 1: Fatal error: Index out of range when pulling up data in UITableView

ios - Swift UIViewController子类实例变量初始化策略

带有 segue 的标签栏嵌入 Swift 导航 Controller

ios - 如何在 swift 中使用 `if case` 语句作为 bool 值