pclass.h 2.77 KB
Newer Older
Robert Ricci's avatar
Robert Ricci committed
1
2
3
4
5
6
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2003 University of Utah and the Flux Group.
 * All rights reserved.
 */

Christopher Alfeld's avatar
   
Christopher Alfeld committed
7
8
9
#ifndef __PCLASS_H
#define __PCLASS_H

10
11
12
// Declared in assign.cc - indicated whether or not we should use pclasses
extern bool use_pclasses;

Christopher Alfeld's avatar
   
Christopher Alfeld committed
13
14
15
16
// tb pnode list is a data structure that acts like list but has
// O(1) removal.  It is a list of tb_pnode*.
class tb_pnodelist {
public:
17
18
19
20
21
  typedef list<tb_pnode*> pnode_list;
  typedef pnode_list::iterator list_iter;
  pnode_list L;
  typedef hash_map<tb_pnode*,list_iter,hashptr<tb_pnode*> > pnode_iter_map;
  pnode_iter_map D;
Christopher Alfeld's avatar
   
Christopher Alfeld committed
22

23
24
25
26
  list_iter push_front(tb_pnode *p) {
    L.push_front(p);
    list_iter it = L.begin();
    D[p]=it;
Christopher Alfeld's avatar
   
Christopher Alfeld committed
27
28
    return it;
  };
29
30
31
32
33
  list_iter push_back(tb_pnode *p) {
    L.push_back(p);
    list_iter it = L.end();
    it--;
    D[p]=it;
Christopher Alfeld's avatar
   
Christopher Alfeld committed
34
35
36
37
    return it;
  };
  int remove(tb_pnode *p) {
    if (exists(p)) {
38
39
40
      pnode_iter_map::iterator dit = D.find(p);
      L.erase((*dit).second);
      D.erase(dit);
Christopher Alfeld's avatar
   
Christopher Alfeld committed
41
42
43
44
45
46
      return 0;
    } else {
      return 1;
    }
  };
  int exists(tb_pnode *p) {
47
    return (D.find(p) != D.end());
Christopher Alfeld's avatar
   
Christopher Alfeld committed
48
49
  }
  tb_pnode *front() {
50
    return (L.empty() ? NULL : L.front());
Christopher Alfeld's avatar
   
Christopher Alfeld committed
51
  };
52
53
54
55
56
57
58
59
60

  friend ostream &operator<<(ostream &o, const tb_pnodelist& l)
  {
    pnode_list::const_iterator lit;
    for (lit=l.L.begin();lit!=l.L.end();++lit) {
      o << "    " << (*lit)->name << endl;
    }
    return o;
  }
Christopher Alfeld's avatar
   
Christopher Alfeld committed
61
62
63
64
};

class tb_pclass {
public:
65
66
67
68
69
70
  tb_pclass() : size(0), used(0) {;}

  typedef hash_map<crope,tb_pnodelist*> pclass_members_map;
  typedef hash_set<tb_pnode*,hashptr<tb_pnode*> > tb_pnodeset;
  typedef hash_map<crope,tb_pnodeset*> pclass_members_set;

Christopher Alfeld's avatar
   
Christopher Alfeld committed
71
72
  int add_member(tb_pnode *p);

73
  crope name;			// purely for debugging
Christopher Alfeld's avatar
   
Christopher Alfeld committed
74
75
  int size;
  double used;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  pclass_members_map members;
#ifdef SMART_UNMAP
  pclass_members_set used_members;
#endif

  friend ostream &operator<<(ostream &o, const tb_pclass& p)
  {
    o << p.name << "(" << &p << ") size=" << p.size <<
      " used=" << p.used << "\n";
    pclass_members_map::const_iterator dit;
    for (dit=p.members.begin();dit!=p.members.end();++dit) {
      o << "  " << (*dit).first << ":\n";
      o << *((*dit).second) << endl;
    }
    o << endl;
    return o;
  }
Christopher Alfeld's avatar
   
Christopher Alfeld committed
93
94
95
};

typedef list<tb_pclass*> pclass_list;
96
97
98
typedef vector<tb_pclass*> pclass_vector;
typedef pair<int,pclass_vector*> tt_entry;
typedef hash_map<crope,tt_entry> pclass_types;
Christopher Alfeld's avatar
   
Christopher Alfeld committed
99
100
101
102
103
104
105
106
107
108
109
110

/* Constants */
#define PCLASS_BASE_WEIGHT 1
#define PCLASS_NEIGHBOR_WEIGHT 1
#define PCLASS_UTIL_WEIGHT 1
#define PCLASS_FDS_WEIGHT 2

/* routines defined in pclass.cc */
int generate_pclasses(tb_pgraph &PG);// sets pclasses and type_table globals

/* The following two routines sets and remove mappings in pclass
   datastructures */
111
112
int pclass_set(tb_vnode *v,tb_pnode *p);
int pclass_unset(tb_pnode *p);
Christopher Alfeld's avatar
   
Christopher Alfeld committed
113

114
void pclass_debug();
Christopher Alfeld's avatar
   
Christopher Alfeld committed
115
116

#endif