This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Levenshtein { | |
private(set) var cache = [Set<String.SubSequence>: Int]() | |
func calculateDistance(a: String.SubSequence, b: String.SubSequence) -> Int { | |
let key = Set([a, b]) | |
if let distance = cache[key] { | |
return distance | |
} else { | |
let distance: Int = { | |
if a.count == 0 || b.count == 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public class Vertex { | |
var key: String? | |
var neighbors: Array<Edge> | |
init() { | |
self.neighbors = Array<Edge>() | |
} | |
} |