Skip to content

Instantly share code, notes, and snippets.

@chriswebb09
Created May 19, 2017 20:50
Show Gist options
  • Save chriswebb09/09ab178a5935fbc175cdb3ce86a0e70d to your computer and use it in GitHub Desktop.
Save chriswebb09/09ab178a5935fbc175cdb3ce86a0e70d to your computer and use it in GitHub Desktop.
struct HashTable<Key: Hashable, Value> {
// Prior Hash Table Implementation
func model(with element: Key) -> String? {
switch element {
case is String:
return String(describing: element)
case is Int:
let stringElement = String(describing: element)
return stringElement
default:
return nil
}
}
subscript(key: Key) -> Value? {
get {
return value(for: key)
}
set {
if let value = newValue {
updateValue(value, forKey: key)
} else {
removeValue(for: key)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment