根据时间和类型生成一个唯一的id
2016-07-20 10:18
441 查看
NLMISC::CEntityId CNewIdBuilder::getNewEntityId()
{
uint32 now = NLMISC::CTime::getSecondsSince1970();
if (now > mCreateIdLastTime)
{
mCreateIdLastTime = now;
mShortId = 0;
}
if (mShortId >= MAX_ID_PER_SEC)
{
++mCreateIdLastTime;
mShortId = 0;
nlwarning("getNewEntityId typeId = [%d] diff = [%d]", mTypeId, (mCreateIdLastTime - now));
}
uint32 fullId = (uint32)(mCreateIdLastTime<<5) + mShortId;
++mShortId;
return NLMISC::CEntityId(mTypeId, fullId);
}
{
uint32 now = NLMISC::CTime::getSecondsSince1970();
if (now > mCreateIdLastTime)
{
mCreateIdLastTime = now;
mShortId = 0;
}
if (mShortId >= MAX_ID_PER_SEC)
{
++mCreateIdLastTime;
mShortId = 0;
nlwarning("getNewEntityId typeId = [%d] diff = [%d]", mTypeId, (mCreateIdLastTime - now));
}
uint32 fullId = (uint32)(mCreateIdLastTime<<5) + mShortId;
++mShortId;
return NLMISC::CEntityId(mTypeId, fullId);
}
相关文章推荐
- linux下进度条的简单实现
- js 把xml与json互相转化
- 【杭电】[2504]又见GCD
- KVO
- linux管理员权限解析及LAMP环境的安装
- 使用Fuel自动化部署Openstack
- 设计模式——组合模式
- 什么是 MTU, 什么是 MSS
- PHP采集curl应用的一点小疑惑
- elasticsearch + hive环境搭建
- erlang,elixir安装
- SharedPreference 缓存
- 多消费者与多生产者
- Codeforces Round #363 (Div. 2) D. Fix a Tree (并查集)
- java学习--构造函数
- linux查看硬件信息命令
- 存储过程的基本语法
- spring mybatis多数据源实例详解
- Codeforces Round #361 (Div. 2)
- KVO