2 ms·
a map is a set indexed only on a subset of the fields of your type. This maps directly to the relational model, where a table (or relation) being a set of tupl
by gpderetta 6y ago
a map is a set indexed only on a subset of the fields of your type.
This maps directly to the relational model, where a table (or relation) being a set of tuples is the fundamental concept: for your typical programming language set the uniqueness constraint (and key), would be comprised by all the columns, while for a map it would only be comprised by a subset (just one at the limit), while the remaining columns would be the mapped type.
Set operations (union, intersection, difference) do make sense for maps as well in fact.
Given a powerful enough language, you can generalize your sets and maps with multiple uniqueness constraints and secondary indices. See boost.multindex for example.
edit: and BTW, most STL implementations use the same underlying implementation for std::set and std::map which has a set-like interface with the ability to specify the key mapping function.