We discussed sets and maps briefly during the F# primer. Sets are standard data structures in most functional languages. In F#, these key data structures are also supported along with lists and sequences, and are implemented as immutable AVL trees. An AVL tree, named for G. Adelson-Velsky and E. M. Landis, is a self-balancing binary search tree that is an efficient data structure. AVL trees support insertion, deletion, and search operations in time where n is the number of nodes (elements). Nodes are often referred to as elements as they are used to store the values (elements) in the tree.
A set collection is a container for unique items as it does not allow duplicates. Sets do not preserve the order in which the elements are inserted. Following is an example of Set
:
Set.empty.Add(3).Add(2).Add(7);; val it : Set<int> = set [1; 2; 7]
Another data structure implementation, similar to sets, is map. A map is basically a dictionary, that is, a special kind of set which associates...