2017-07-17 04:36:38 +02:00
|
|
|
|
//
|
|
|
|
|
// DatabaseID.swift
|
|
|
|
|
// Data
|
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 7/15/17.
|
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
// MD5 works because:
|
|
|
|
|
// * It’s fast
|
|
|
|
|
// * Collisions aren’t going to happen with feed data
|
|
|
|
|
|
2017-09-02 23:19:42 +02:00
|
|
|
|
private var databaseIDCache = [String: String]()
|
|
|
|
|
|
2017-07-17 04:36:38 +02:00
|
|
|
|
public func databaseIDWithString(_ s: String) -> String {
|
|
|
|
|
|
2017-09-02 23:19:42 +02:00
|
|
|
|
if let identifier = databaseIDCache[s] {
|
|
|
|
|
return identifier
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let identifier = (s as NSString).rs_md5Hash()
|
|
|
|
|
databaseIDCache[s] = identifier
|
|
|
|
|
return identifier
|
2017-07-17 04:36:38 +02:00
|
|
|
|
}
|