IDGenerator.h 1.5 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

X
Xu Peng 已提交
18
#pragma once
19

X
Xu Peng 已提交
20
#include "Types.h"
21

22 23 24
#include <cstddef>
#include <vector>

X
Xu Peng 已提交
25
namespace zilliz {
J
jinhai 已提交
26
namespace milvus {
X
Xu Peng 已提交
27
namespace engine {
28 29

class IDGenerator {
J
jinhai 已提交
30
 public:
S
starlord 已提交
31 32
    virtual IDNumber
    GetNextIDNumber() = 0;
33 34

    virtual void
S
starlord 已提交
35
    GetNextIDNumbers(size_t n, IDNumbers& ids) = 0;
36

S
starlord 已提交
37 38
    virtual ~IDGenerator() = 0;
};  // IDGenerator
39 40

class SimpleIDGenerator : public IDGenerator {
J
jinhai 已提交
41 42 43 44 45 46 47
 public:
    ~SimpleIDGenerator() override = default;

    IDNumber
    GetNextIDNumber() override;

    void
S
starlord 已提交
48
    GetNextIDNumbers(size_t n, IDNumbers& ids) override;
J
jinhai 已提交
49 50 51

 private:
    void
S
starlord 已提交
52
    NextIDNumbers(size_t n, IDNumbers& ids);
53

J
jinhai 已提交
54
    static constexpr size_t MAX_IDS_PER_MICRO = 1000;
S
starlord 已提交
55
};  // SimpleIDGenerator
56

S
starlord 已提交
57 58 59
}  // namespace engine
}  // namespace milvus
}  // namespace zilliz