开发者

Generating a unique id of std::string

I want to generate any limited std::string size unique id 开发者_运维知识库(i.e of size 6) in 32 bit application. what would be the best and quick way to do this?


Look up hashing of strings, e.g. the Jenkins hash function.

But you will never get unique hashes, because strings can be much longer than your size 6, and the Pigoenhole lemma shows trivially that hashes must collide as a a consequence.


Very difficult to tell from your question what you are asking, but the following generates strings in the sequence "1", "2", "3":

#include <string>
#include <sstream>

std::string GetUniqueId() {
   static int n = 1;
   std::ostringstream os;
   os << n++;
   return os.str();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜