惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
小众软件
小众软件
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 聂微东
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
MyScale Blog
MyScale Blog

博客园 - 农民伯伯

【读书笔记】达利欧 - 《原则:应对变化中的世界秩序》 【读书笔记】余华 - 活着 Mixin 工作原理 公链 - 达世币(Dash) 公链 - 比原链(Bytom) 公链 - Horizen 公链 - 以太坊(Ethereum) 公链 - Filecoin 公链 - EOS 公链 - 门罗币(Monero) 公链 - 比特币(Bitcoin) Git 简易手册 三大运营商手机号段发布时间汇总 中英文混排指南 - 简化版 iOS Share Extension 自定义分享界面 Mixin Messenger 源码解读 1 — — WCDB Swift 2018 年流水账 区块链代币(Token)笔记 — — 术语 【Swift 4.0】扩展 WCDB 支持 SQL 语句
【Swift 4.2】uuid 取 hashCode(与 Java/Go/Kotlin 一致) -...
农民伯伯 · 2019-02-25 · via 博客园 - 农民伯伯
extension String {

    func hashCode() -> Int32 {
        let components = self.split(separator: "-")

        var mostSigBits = Int64(components[0], radix: 16)!
        mostSigBits <<= 16

        let c1 = Int64(components[1], radix: 16)!
        mostSigBits |= c1
        mostSigBits <<= 16
        let c2 = Int64(components[2], radix: 16)!
        mostSigBits |= c2

        var leastSigBits = Int64(components[3], radix: 16)!
        leastSigBits <<= 48
        let c4 = Int64(components[4], radix: 16)!
        leastSigBits |= c4

        let hilo = mostSigBits ^ leastSigBits

        return Int32(truncatingIfNeeded: hilo>>32) ^ Int32(truncatingIfNeeded: hilo)
    }
}

在 Playground 里面用 "c2ab81d4-2226-4d0c-a49a-dc59b34f7972" 测试输出 "-145200653"