Efficient data structure to get an ID
I need an efficient data structure to generate IDs. The IDs should be able to be released using a method in the data structure. After an ID was released it can be generate开发者_如何学Cd again. The data structure must always retrieve the lowest unused ID.
What efficient data structure can be used for this?Can't you just increment an integer and return that, with appropriate currency control. If someone releases an integer back store that in another sorted data structure and return that. If the list of returned integers is empty then your return is a simple as read, increment, write, return. If the list of returned integers is not empty then just read, return and remove the first int from the returned integers list
精彩评论