Data Structures and Algorithms in Swift with generics