Fastest container or algorithm for unique reusable ids in C++

前端 未结 8 886
暗喜
暗喜 2021-02-04 10:33

I have a need for unique reusable ids. The user can choose his own ids or he can ask for a free one. The API is basically

class IdManager {
public:
  int Allocat         


        
8条回答
  •  终归单人心
    2021-02-04 10:49

    But I don't think you have to guarantee the id must starts from 1. You can just make sure the available id must be larger than all allocated ids.

    Like if the 3 is registered first, then the next available id can just be 4. I don't think it is necessary to use 1.

提交回复
热议问题