-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
Dictionary types, also referred to as associative arrays or simply maps, are an important data structure in many types of programs. Conceptually, they map a series of keys to a single value each, where the key and value may be different types. We'll examine how Rust implements maps in this section, and we'll also examine their close cousin, the set, which is a special case of a map with no values. Both map and set types will collectively be referred to as dictionary types throughout this section.
Rust offers two "flavors" of map and set structures in its standard library. The first flavor is the hash flavor. The HashMap and HashSet types in the std::collections module store their data by creating a hash of the key and using that hash to pick a spot in memory to store the value. This means that the internal data is not sorted in any useful, human-interpretable way. The hash flavor roughly corresponds...