DataObj.h 1.7 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.

G
groot 已提交
18 19 20

#pragma once

21
#include "src/wrapper/VecIndex.h"
G
groot 已提交
22

G
groot 已提交
23 24 25
#include <memory>

namespace zilliz {
J
jinhai 已提交
26
namespace milvus {
G
groot 已提交
27 28 29
namespace cache {

class DataObj {
S
starlord 已提交
30 31 32 33
 public:
    explicit DataObj(const engine::VecIndexPtr &index)
        : index_(index) {
    }
G
groot 已提交
34

S
starlord 已提交
35 36 37 38
    DataObj(const engine::VecIndexPtr &index, int64_t size)
        : index_(index),
          size_(size) {
    }
S
starlord 已提交
39

S
starlord 已提交
40 41 42 43 44 45 46
    engine::VecIndexPtr data() {
        return index_;
    }

    const engine::VecIndexPtr &data() const {
        return index_;
    }
G
groot 已提交
47 48

    int64_t size() const {
S
starlord 已提交
49
        if (index_ == nullptr) {
G
groot 已提交
50 51
            return 0;
        }
G
groot 已提交
52

S
starlord 已提交
53
        if (size_ > 0) {
S
starlord 已提交
54 55 56
            return size_;
        }

X
xj.lin 已提交
57
        return index_->Count() * index_->Dimension() * sizeof(float);
G
groot 已提交
58
    }
G
groot 已提交
59

S
starlord 已提交
60
 private:
S
starlord 已提交
61
    engine::VecIndexPtr index_ = nullptr;
S
starlord 已提交
62
    int64_t size_ = 0;
G
groot 已提交
63 64 65 66
};

using DataObjPtr = std::shared_ptr<DataObj>;

S
starlord 已提交
67 68 69
} // namespace cache
} // namespace milvus
} // namespace zilliz