pclass.h 1.79 KB
Newer Older
1 2 3 4 5 6
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2002 University of Utah and the Flux Group.
 * All rights reserved.
 */

7 8 9 10 11 12 13
#ifndef __PCLASS_H
#define __PCLASS_H

// 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:
14 15
  list<tb_pnode*> L;
  dictionary<tb_pnode*,list_item> D;
16

17 18 19
  list_item push_front(tb_pnode *p) {
    list_item it = L.push_front(p);
    D.insert(p,it);
20 21
    return it;
  };
22 23 24
  list_item push_back(tb_pnode *p) {
    list_item it = L.push_back(p);
    D.insert(p,it);
25 26 27 28
    return it;
  };
  int remove(tb_pnode *p) {
    if (exists(p)) {
29 30 31
      list_item it = D.access(p);
      L.del_item(it);
      D.del(p);
32 33 34 35 36 37
      return 0;
    } else {
      return 1;
    }
  };
  int exists(tb_pnode *p) {
38
    return (D.lookup(p) != nil);
39 40
  }
  tb_pnode *front() {
41 42
    list_item it = L.first();
    return ((it == nil) ? NULL : L[it]);
43 44 45 46 47
  };
};

class tb_pclass {
public:
48 49 50 51 52
  tb_pclass() {
    size=0;
    used=0;
  }
  
53 54
  int add_member(tb_pnode *p);

55
  string name;			// purely for debugging
56 57
  int size;
  double used;
58
  dictionary<string,tb_pnodelist*> members;
59 60 61
};

typedef list<tb_pclass*> pclass_list;
62 63 64
typedef array<tb_pclass*> pclass_array;
typedef two_tuple<int,pclass_array*> tt_entry;
typedef dictionary<string,tt_entry> pclass_types;
65 66 67 68 69 70 71 72 73 74 75 76

/* 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 */
77 78
int pclass_set(tb_vnode &v,tb_pnode &p);
int pclass_unset(tb_pnode &p);
79

80 81
void pclass_debug();		// dumps debug info
int compare(tb_pclass *const &, tb_pclass *const &);
82 83

#endif