Created
May 19, 2017 20:50
-
-
Save chriswebb09/09ab178a5935fbc175cdb3ce86a0e70d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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