mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-30 23:45:28 +08:00
56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
|
|
// Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
// Proprietary and confidential.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include <chrono>
|
|
#include <assert.h>
|
|
#include <iostream>
|
|
|
|
#include "IDGenerator.h"
|
|
|
|
|
|
namespace zilliz {
|
|
namespace vecwise {
|
|
namespace engine {
|
|
|
|
IDGenerator::~IDGenerator() {}
|
|
|
|
IDNumber SimpleIDGenerator::getNextIDNumber() {
|
|
auto now = std::chrono::system_clock::now();
|
|
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(
|
|
now.time_since_epoch()).count();
|
|
return micros * MAX_IDS_PER_MICRO;
|
|
}
|
|
|
|
void SimpleIDGenerator::nextIDNumbers(size_t n, IDNumbers& ids) {
|
|
if (n > MAX_IDS_PER_MICRO) {
|
|
nextIDNumbers(n-MAX_IDS_PER_MICRO, ids);
|
|
nextIDNumbers(MAX_IDS_PER_MICRO, ids);
|
|
return;
|
|
}
|
|
if (n <= 0) {
|
|
return;
|
|
}
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(
|
|
now.time_since_epoch()).count();
|
|
micros *= MAX_IDS_PER_MICRO;
|
|
|
|
for (int pos=0; pos<n; ++pos) {
|
|
ids.push_back(micros+pos);
|
|
}
|
|
|
|
}
|
|
|
|
void SimpleIDGenerator::getNextIDNumbers(size_t n, IDNumbers& ids) {
|
|
ids.clear();
|
|
nextIDNumbers(n, ids);
|
|
}
|
|
|
|
|
|
} // namespace engine
|
|
} // namespace vecwise
|
|
} // namespace zilliz
|