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

X
xiaojun.lin 已提交
21
#include "src/wrapper/vec_index.h"
G
groot 已提交
22

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

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

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

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

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

    int64_t size() const {
        if(index_ == nullptr) {
            return 0;
        }
G
groot 已提交
47

S
starlord 已提交
48 49 50 51
        if(size_ > 0) {
            return size_;
        }

X
xj.lin 已提交
52
        return index_->Count() * index_->Dimension() * sizeof(float);
G
groot 已提交
53
    }
G
groot 已提交
54 55

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

using DataObjPtr = std::shared_ptr<DataObj>;

}
}
}