Hello ,

I have map of the following type:
typedef map < int, vectorofInts > ,

Now the map has finite size. Each user when he registers, he will be allocated a key.
Lets say the map size is 4.

U1 will be allocated in K1.
next U2 on K2, U3 on K3, U4 on K4.

Later it happens in round robin way, U5 with K1 etc.

Meantime, U1 may dropoff, in that case U6, needs to be allocated K1. to keep uniformity.

Any feedback or idea regarding this alogrithm and optimum way to implement. Sorry that i am not c++ stl expert, working occasionally on this.

This is somewhat smaller version of the legacy program i have written to the one from the legacy code. Sorry for my poor c++ STL skills. Looking for the AddNewUser() function implementation.

#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef vector<int> int_vect;
typedef pair < int, int_vect > IntPair ;
typedef map<int,int_vect> outerarray;
outerarray outarr;
int_vect v0;

int AddNewUser()
{

}

int main()
{
   // vector of users
   int_vect v0;

   outarr.insert(std::make_pair(1, v0));
   outarr.insert(std::make_pair(2, v0));
   outarr.insert(std::make_pair(3, v0));
   outarr.insert(std::make_pair(4, v0));

   // Add a new User

   AddNewUser();


}

thanks
pdk

Your code doesn't seem to match your description. Does the key represent a user or a user group? This is confusing because you've commented the int_vect as a vector of users. Does this mean that you want to add, remove, or move users from one vector or another? Or do you want to add,remove, or move the vectors?

Thanks a lot for the reply.

Yes, i.e true. I found later, it is good to have "set" rather than "vector" for the list of users. Where i can add , remove the users from the set, corresponding to a lets say "user group id". I think it was wrong for me to use the term key.

If this question no longer applies, you should mark it as solved. If you have more questions or different code you should start a new question. Thanks.

Thanks a lot for the reply.

Yes, i.e true. I found later, it is good to have "set" rather than "vector" for the list of users. Where i can add , remove the users from the set, corresponding to a lets say "user group id". I think it was wrong for me to use the term key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.