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> { | |
| // Hash table setup | |
| func index(for key: Key) -> Int { | |
| var divisor: Int = 0 | |
| for key in String(describing: key).unicodeScalars { | |
| divisor += abs(Int(key.value.hashValue)) | |
| } | |
| return abs(divisor) % buckets.count | |
| } | |
| } |
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> { | |
| typealias Bucket = [HashElement<Key, Value>] | |
| var buckets: [Bucket] | |
| init(capacity: Int) { | |
| assert(capacity > 0) | |
| buckets = Array<Bucket>(repeatElement([], count: capacity)) | |
| } |
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
| class HashElement<T: Hashable, U> { | |
| var key: T | |
| var value: U? | |
| init(key: T, value: U?) { | |
| self.key = key | |
| self.value = value | |
| } | |
| } |
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 Stack<T> { | |
| var isEmpty: Bool { | |
| return items.isEmpty | |
| } | |
| var count: Int { | |
| return items.count | |
| } | |
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 Queue<T> { | |
| var list = LinkedList<T>() | |
| mutating func enqueue(_ element: T) { | |
| list.append(value: element) | |
| } | |
| mutating func dequeue() -> T? { | |
| guard !list.isEmpty, let element = list.first else { return nil } |
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
| import UIKit | |
| class PlaylistItem { | |
| var track: iTrack? | |
| var next: PlaylistItem? | |
| weak var previous: PlaylistItem? | |
| } | |
| extension PlaylistItem: Equatable { | |
| static func ==(lhs: PlaylistItem, rhs: PlaylistItem) -> Bool { |
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
| class LinkedList<T> { | |
| public typealias Node = LLNode<T> | |
| private var head: Node? | |
| private var tail: Node? | |
| var isEmpty: Bool { | |
| return head == nil | |
| } |
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
| class LLNode<T> { | |
| var value: T | |
| var next: LLNode? | |
| weak var previous: LLNode? | |
| init(value: T) { | |
| self.value = value | |
| } | |
| } |
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
| import UIKit | |
| class PlaylistItem { | |
| var track: iTrack? | |
| var next: PlaylistItem? | |
| weak var previous: PlaylistItem? | |
| } | |
| extension PlaylistItem: Equatable { | |
| static func ==(lhs: PlaylistItem, rhs: PlaylistItem) -> Bool { |
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
| import UIKit | |
| class Playlist { | |
| private var head: PlaylistItem? | |
| var itemCount: Int = 0 | |
| var isEmpty: Bool? { | |
| return head == nil |