1

I need to create a mapping records of users and applications (many to many model) in c++. One users can have many applications connected to it, and vice versa, one application can have many users connected to it.
I have 2 design model, as follow:
First Design

unordered_map <string, unordered_set<string> > OneToManyMapping;
OneToManyMapping userAppMappings; // mapping records of 1 user to all application that it connects to.
OneToManyMapping appUserMappings; // mapping records of 1 application to all users that connects to it.

So every time a user is connected to new applications, we do not have to create a new record, but just insert the new application id to the unordered_set element of the userAppMappings. And same case for the appUserMappings. (every time a new user connects to it, we just insert the new user Id to the unordered_set element of the appUserMappings.

Second Design

unordered_multimap <string, string > ManyToManyMapping;
ManyToManyMappings userAppMappings; // mapping records of many user to many applications.
ManyToManyMappings appUserMappings; // mapping records of many applications to all users.

Every time a user is connected to a new application, we have to create new record on the userAppMappings. Same case with the appUserMappings.

Which design would be the most efficient if I want it to support the following operations:

Insertion,
Deletion,
Access (get list of all applications, or list of all users, or get list of all applications which is connected to a user, or get list of all users connected to an application ),
Delete all applications connected to a user, delete all users connected to an application, etc?

What will be the pro and cons if I use the first design or the second design? Is mapping the ID of the user and application a good approach, or is it better to map the complete User object and Application object?
Is there any other better design? Please advise.

all_by_grace
  • 2,315
  • 6
  • 37
  • 52

1 Answers1

0

Your second design will not work as many to many mapping, unordered_map key should be unique, that is you will not be able to store different records for the same user/application. What you are asking is multimap container, see http://en.wikipedia.org/wiki/Multimap.

Alexander B
  • 407
  • 2
  • 17
  • Yes, sorry for the typo. The second design is based on unordered_multimap. Thanks for mentioning. I have updated the post ! – all_by_grace Oct 08 '11 at 19:48