aboutsummaryrefslogtreecommitdiffstats
path: root/vdslib/src/vespa/vdslib/state/idealgroup.h
blob: 9dcfde3e18537fcd53f710700de65ef558cf18ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @class vdslib::IdealGroup
 *
 * Points to a Group object that has been picked for
 * distribution with a given redundancy.
 *
 *
 */
#pragma once

#include <vdslib/state/group.h>
#include <vespa/vespalib/objects/floatingpointtype.h>

namespace storage {
namespace lib {

class IdealGroup : public document::Printable
{
    const Group* _group;
    double _score;
    double _redundancy;

public:
    IdealGroup() {};

    IdealGroup(const Group& group, double score, double redundancy);

    virtual void print(std::ostream& out, bool verbose,
                       const std::string& indent) const;

    double getRedundancy() const {return _redundancy;}

    void setRedundancy(double redundancy) {_redundancy = redundancy;}

    double getScore() const {return _score;}

    static bool sortScore (IdealGroup ig1, IdealGroup ig2)
    {
        return (ig1._score<ig2._score);
    }

    static bool sortRedundancy (IdealGroup ig1, IdealGroup ig2)
    {
        return (ig1._redundancy<ig2._redundancy);
    }

    const std::vector<uint16_t>& getNodes() const
    {
        return _group->getNodes();
    }

    const Group& getGroup() const {
        return *_group;
    }

};

} // lib
} // storage