Collection Data Structures In Swift

*An NSArray is heterogeneous, meaning that it can contain Cocoa objects of different types. Swift arrays are homogeneous, meaning that each Swift Array is guaranteed to contain only one type of object. 

However, you can still define a single Swift Array so it stores various types of Cocoa objects by specifying that the one type is AnyObject, since every Cocoa type is also a subtype of this. 


*Dictionaries are strongly typed, and you must have known key and value types. NSDictionary objects are able to take any NSObject as a key and store any object as a value.


*Note that subscripting syntax on dictionaries returns an optional. If the dictionary doesn't contain a value for a particular key, the optional is nil; if it does contain a value for that key you could get the wrapped value.

if let ellensCat = cats["Ellen"] {
	println("Ellen's cat is named \(ellensCat).")
} else {
	println("Ellen's cat's name not found!")
}

Because of that, it's a good idea to use the if let optional-unwrapping syntax to access values in a dictionary.


*Swift sets are type-specific -- all the items in a Swift Set must be of the same type.


*Creating Swift dictionaries is significantly slower than creating NSMutableDictionaries -- but both degrade at roughly the same O(n) rate.


*Set creation is considerably slower -- that's the price you pay for checking if every single item in a data structure is unique. 


*Removing and looking up are both around O(1) performance degradations across Swift and Foundation. This is largely because set structures use hashes to check for equality, and the hashes can be calculated and stored in sorted order. This makes set lookup considerably faster than array lookup.


*NSCountedSet tracks how many times you've added an object to a mutable set. It inherits from NSMutableSet, so if you try to add the same object again, it's only in the set once. 


*NSOrderedSet inherits from NSObject.


*You can use ordered sets as an alternative to arrays when element order matters and performance while testing whether an object is contained in the set is a consideration -- testing for membership of an array is slower than testing for membership of a set. 


*An NSIndexSet is an immutable collection of unique unsigned integers intended to represent indexes of an array. 


Learn data structures and algorithms in Swift! Understanding how data structures and algorithms work in code is crucial for creating efficient and scalable apps. Swift’s Standard Library has a small set of general purpose collection types, yet they definitely don’t cover every case! In this book, you’ll learn how to implement the most popular and useful data structures, and when and why you should use one particular data structure or algorithm over another. This set of basic data structures and algorithms will serve as an excellent foundation for building more complex and special-purpose constructs. As well, the high-level expressiveness of Swift makes it an ideal choice for learning these core concepts without sacrificing performance. Who This Book Is For This book is for developers who are comfortable with Swift and want to ace whiteboard interviews, improve the performance of their code, and ensure their apps will perform well at scale. Topics Covered in Data Structures & Algorithms in Swift * Basic structures: Start with the fundamental structures of linked lists, queues and stacks, and see how to implement them in a highly Swift-like way. * Trees: Learn how to work with various types of trees, including general purpose trees, binary trees, AVL trees, binary search trees, and tries. * Sorting: Go beyond bubble and insertion sort with better-performing algorithms, including mergesort, radix sort, heap sort, and quicksort. * Graphs: Learn how to construct directed, non-directed and weighted graphs to represent many real-world models. * Traversals: Traverse graphs and trees efficiently with breadth-first, depth-first, Dijkstra’s and Prim’s algorithms to solve problems such as finding the shortest path or lowest cost in a network. * And much, much more! By the end of this book, you’ll have hands-on experience solving common issues with data structures and algorithms — and you’ll be well on your way to developing your own efficient and useful implementations!
Swift Data Structure and Algorithms by Erik Azar English | 18 Nov. 2016 | ISBN: 1785884506 | 286 Pages | AZW3/MOBI/EPUB/PDF (conv) | 22.7 MB Master the most common algorithms and data structures, and learn how to implement them efficiently using the most up-to-date features of Swift 3 About This Book Develop a deep understanding of the collections in the Swift Standard Library with this step-by-step guide Develop native Swift data structures and algorithms for use in mobile, desktop, and server-based applications Learn about performance efficiency between different data structures and algorithms Who This Book Is For This book is for developers who want to learn how to implement and use common data structures and algorithms natively in Swift. Whether you are a self-taught developer without a formal technical background or you have a degree in Computer Science, this book will provide with the knowledge you need to develop advanced data structures and algorithms in Swift using the latest language features. What You Will Learn Get to know about the basic data structures and how to use the Swift REPL Use the Swift Standard Library collections bridging to Objective-C collections, and find out about protocol-oriented programming Find out about Swift generators and sequences, and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList Implement sorting algorithms such as Insertion Sort, Merge Sort, and Quick Sort and understand the performance trade-offs between them See how to implement various binary trees, B-Tree, and Splay Trees Perform advanced searching methods using Red-Black trees, AVL trees, and Trie trees, and take a look at several substring search algorithms Get to know about the data structures used in graphs and how to implement graphs such as depth-first search, breadth-first search, directed graphs, spanning tree, and shortest path Explore algorithm efficiency and see how to measure it
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值