假设我有以下的用户结构:存储元素VS它们存储在一个unordered_map
struct User {
string userId;
UserType userType; // UserType is just an enumeration
string hostName;
string ipAddress;
//and more other attributes will be added here
};
,我需要存储的用户记录的集合(约10^5个用户,可以扩展也比较高)。如果将它作为unordered_set或unordered_map存储,性能会更好吗? Unordered_set在技术上与HashSet相同,而unordered_map与HashMap相同,对吗?使用常规集合(有序)不是一种选择,因为插入和删除操作会在元素数量增加时变得非常慢。
unordered_set <User> userRecords;
OR
unordered_map <string, User> userRecords; // string is the user ID.
我需要它是非常快,插入,删除的条款,并通过它的用户id访问一个特定的用户对象。