VecIdMapper.h 2.5 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

G
groot 已提交
8 9 10 11 12 13
#include "utils/Error.h"

#include <string>
#include <vector>
#include <unordered_map>

G
groot 已提交
14 15 16 17
namespace rocksdb {
    class DB;
}

G
groot 已提交
18 19 20 21
namespace zilliz {
namespace vecwise {
namespace server {

G
groot 已提交
22
class IVecIdMapper {
G
groot 已提交
23
public:
G
groot 已提交
24 25 26
    static IVecIdMapper* GetInstance();

    virtual ~IVecIdMapper(){}
G
groot 已提交
27

G
groot 已提交
28 29 30
    virtual ServerError AddGroup(const std::string& group) = 0;
    virtual bool IsGroupExist(const std::string& group) const = 0;

G
groot 已提交
31 32
    virtual ServerError Put(const std::string& nid, const std::string& sid, const std::string& group = "") = 0;
    virtual ServerError Put(const std::vector<std::string>& nid, const std::vector<std::string>& sid, const std::string& group = "") = 0;
G
groot 已提交
33

G
groot 已提交
34
    virtual ServerError Get(const std::string& nid, std::string& sid, const std::string& group = "") const = 0;
G
groot 已提交
35
    //NOTE: the 'sid' will be cleared at begin of the function
G
groot 已提交
36
    virtual ServerError Get(const std::vector<std::string>& nid, std::vector<std::string>& sid, const std::string& group = "") const = 0;
G
groot 已提交
37

G
groot 已提交
38
    virtual ServerError Delete(const std::string& nid, const std::string& group = "") = 0;
G
groot 已提交
39
    virtual ServerError DeleteGroup(const std::string& group) = 0;
G
groot 已提交
40 41
};

G
groot 已提交
42 43 44 45 46
class SimpleIdMapper : public IVecIdMapper{
public:
    SimpleIdMapper();
    ~SimpleIdMapper();

G
groot 已提交
47 48 49
    ServerError AddGroup(const std::string& group) override;
    bool IsGroupExist(const std::string& group) const override;

G
groot 已提交
50 51
    ServerError Put(const std::string& nid, const std::string& sid, const std::string& group = "") override;
    ServerError Put(const std::vector<std::string>& nid, const std::vector<std::string>& sid, const std::string& group = "") override;
G
groot 已提交
52

G
groot 已提交
53 54
    ServerError Get(const std::string& nid, std::string& sid, const std::string& group = "") const override;
    ServerError Get(const std::vector<std::string>& nid, std::vector<std::string>& sid, const std::string& group = "") const override;
G
groot 已提交
55

G
groot 已提交
56
    ServerError Delete(const std::string& nid, const std::string& group = "") override;
G
groot 已提交
57
    ServerError DeleteGroup(const std::string& group) override;
G
groot 已提交
58 59

private:
G
groot 已提交
60 61
    using ID_MAPPING = std::unordered_map<std::string, std::string>;
    mutable std::unordered_map<std::string, ID_MAPPING> id_groups_;
G
groot 已提交
62 63
};

G
groot 已提交
64 65 66
}
}
}