i have a hashtable of usernames as a key, when a user connects with the same name, i want to add a number to the end. so if "larry" joins, and another joins with the same name i want the new string to be "larry-01". if i search the hashtable, how do i keep track of the number at the end? because if 14 larry's join, and then 10 bob's join, how do i evaluate that? especially if 2 disconnect?

1 answers
Here's a possible way of dealing with that situation.
Basically, when adding a new user, this looks for the highest number of that user's name already present in the hashtable and adds one to it. It doesn't attempt to replace lower numbers which have previously been removed.
So, if you currently have: bob and bob-02 already in the hashtable, the next bob to be added will be bob-03, not the previously removed bob-01.
However, if you originally had: bob, bob-01 and bob-02 and then removed bob-02, the next bob to be added would also be bob-02:
answered one year ago by:
17279