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>

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

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

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

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

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

    IDNumber
    GetNextIDNumber() override;

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

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

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

S
starlord 已提交
56 57
}  // namespace engine
}  // namespace milvus