summaryrefslogtreecommitdiff
path: root/lib/CodeGen/PBQP/Solution.h
blob: 294b5370afdfed2461031c0da045687b207f442c (plain)
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
//===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// PBQP Solution class.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
#define LLVM_CODEGEN_PBQP_SOLUTION_H

#include "Math.h"
#include "Graph.h"

#include <map>

namespace PBQP {

  /// \brief Represents a solution to a PBQP problem.
  ///
  /// To get the selection for each node in the problem use the getSelection method.
  class Solution {
  private:
    typedef std::map<Graph::NodeItr, unsigned, NodeItrComparator> SelectionsMap;
    SelectionsMap selections;

  public:

    /// \brief Number of nodes for which selections have been made.
    /// @return Number of nodes for which selections have been made.
    unsigned numNodes() const { return selections.size(); }

    /// \brief Set the selection for a given node.
    /// @param nItr Node iterator.
    /// @param selection Selection for nItr.
    void setSelection(Graph::NodeItr nItr, unsigned selection) {
      selections[nItr] = selection;
    }

    /// \brief Get a node's selection.
    /// @param nItr Node iterator.
    /// @return The selection for nItr;
    unsigned getSelection(Graph::NodeItr nItr) const {
      SelectionsMap::const_iterator sItr = selections.find(nItr);
      assert(sItr != selections.end() && "No selection for node.");
      return sItr->second;
    }

  };

}

#endif // LLVM_CODEGEN_PBQP_SOLUTION_H