rebuilding basic data structures and algorithms in Swift