vendredi 22 juillet 2016

C++: Generate Unique ids

Generate Unique Ids

FormStrings(unsigned int id, string bigText)
{
    //create small strings from bigText say string1, string2...string k
    for(int x = 0; x< k; ++x)
    unsigned int id uid = generateUniqueId(..);
    ForwardString(uid, stringx)
}

FormStrings() method receives id which starts from 1 and increments ahead as FormStrings() method is called.

FormStrings() method further split the bigText received into smaller strings and passes to other methods.

Requirement is to generate a unique 32 bit id for the new strings created. I should also take care of how many uids are getting created from id, so that if later anyone calls delete id, all the sub-uids string should get deleted.

For example:

FormStrings(1, "Hi, I want to learn cpp.");
string1 = Hi,
String2 = I want to
String3 = learn cpp.

Here id 1 has 3 substrings. I need to create 3 uids.

Next time when FormStrings() method is called, it will come with an id 2, then 3 and so on.

I thought of creating id using 32 bits as 16 bits for id - 65535 ids 8 bits for storing number of strings formed.

but when I ran the actual program, I found out that 65535 is a small number to store id, it could be a very big number(20 bits will also not work), even number of strings formed from bigText is not fixed. I am open to create new variables, structs etc

Any suggestions are welcome.

Aucun commentaire:

Enregistrer un commentaire