Node.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.

W
wxyu 已提交
18 19
#pragma once

X
xj.lin 已提交
20
#include <map>
S
starlord 已提交
21
#include <memory>
S
starlord 已提交
22
#include <string>
S
starlord 已提交
23
#include <vector>
W
wxyu 已提交
24 25

#include "Connection.h"
S
starlord 已提交
26
#include "scheduler/TaskTable.h"
W
wxyu 已提交
27 28 29

namespace zilliz {
namespace milvus {
W
wxyu 已提交
30
namespace scheduler {
W
wxyu 已提交
31 32 33 34 35 36

class Node;

using NeighbourNodePtr = std::weak_ptr<Node>;

struct Neighbour {
S
starlord 已提交
37
    Neighbour(NeighbourNodePtr nei, Connection conn) : neighbour_node(nei), connection(conn) {
S
starlord 已提交
38
    }
W
wxyu 已提交
39

W
wxyu 已提交
40 41 42 43
    NeighbourNodePtr neighbour_node;
    Connection connection;
};

X
xj.lin 已提交
44
// TODO(linxj): return type void -> Status
W
wxyu 已提交
45
class Node {
S
starlord 已提交
46
 public:
X
xj.lin 已提交
47 48
    Node();

W
wxyu 已提交
49
    void
S
starlord 已提交
50
    AddNeighbour(const NeighbourNodePtr& neighbour_node, Connection& connection);
W
wxyu 已提交
51

X
xj.lin 已提交
52 53
    std::vector<Neighbour>
    GetNeighbours();
W
wxyu 已提交
54

S
starlord 已提交
55
 public:
W
wxyu 已提交
56 57 58
    std::string
    Dump();

S
starlord 已提交
59
 private:
X
xj.lin 已提交
60 61 62
    std::mutex mutex_;
    uint8_t id_;
    std::map<uint8_t, Neighbour> neighbours_;
W
wxyu 已提交
63 64
};

W
wxyu 已提交
65 66 67
using NodePtr = std::shared_ptr<Node>;
using NodeWPtr = std::weak_ptr<Node>;

S
starlord 已提交
68 69 70
}  // namespace scheduler
}  // namespace milvus
}  // namespace zilliz