NAMD
Public Member Functions | List of all members
IRSet Class Reference

#include <Set.h>

Inheritance diagram for IRSet:
LargeIRSet

Public Member Functions

 IRSet ()
 
 ~IRSet ()
 
void unchecked_insert (InfoRecord *)
 
void insert (InfoRecord *)
 
int find (InfoRecord *)
 
int remove (InfoRecord *)
 
void myRemove (listNode **n, InfoRecord *r)
 
InfoRecorditerator (Iterator *)
 
InfoRecordnext (Iterator *)
 
int numElements ()
 
int hasElements ()
 
void print ()
 

Detailed Description

Definition at line 25 of file Set.h.

Constructor & Destructor Documentation

IRSet::IRSet ( )

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 17 of file Set.C.

18 {
19  head = (listNode *) 0;
20  nElements = 0;
21 }
Definition: Set.h:12
IRSet::~IRSet ( )

Definition at line 23 of file Set.C.

References listNode::next.

23  {
24  // delete all links; don't delete the InfoRecord objects
25  listNode *tmp;
26  for (listNode *link = head; link; link = tmp) {
27  tmp = link->next;
28  delete link;
29  }
30 }
Definition: Set.h:12
listNode * next
Definition: Set.h:14

Member Function Documentation

int IRSet::find ( InfoRecord r)

Definition at line 112 of file Set.C.

References listNode::info, listNode::next, and Patch::p.

Referenced by Rebalancer::assign(), insert(), Rebalancer::isAvailableOn(), Rebalancer::numAvailable(), and unchecked_insert().

113 {
114  listNode *p = head;
115  while (p) {
116  if (p->info == r) return 1;
117  else p = p->next;
118  }
119  return 0;
120 }
Definition: Set.h:12
InfoRecord *const info
Definition: Set.h:15
listNode * next
Definition: Set.h:14
int IRSet::hasElements ( )

Definition at line 149 of file Set.C.

Referenced by RefineTorusLB::newRefine(), and Rebalancer::refine().

150 {
151  return ! ! head;
152 }
void IRSet::insert ( InfoRecord info)

Definition at line 49 of file Set.C.

References find(), NAMD_bug(), and listNode::next.

Referenced by RefineTorusLB::newRefine(), and Rebalancer::refine().

50 {
51  if (!find(info))
52  {
53  ++nElements;
54  listNode *node = new listNode(info);
55  node->next = head;
56  head = node;
57 #ifdef DEBUG_IRSET
58  int n = 0;
59  while (node) { ++n; node = node->next; }
60  if ( n != nElements ) NAMD_bug("IRSet::insert count");
61 #endif
62  }
63 
64 }
Definition: Set.h:12
void NAMD_bug(const char *err_msg)
Definition: common.C:123
listNode * next
Definition: Set.h:14
int find(InfoRecord *)
Definition: Set.C:112
InfoRecord * IRSet::iterator ( Iterator iter)

Definition at line 122 of file Set.C.

References listNode::info, listNode::next, and Iterator::next.

Referenced by RefineTorusLB::newRefine(), and Rebalancer::refine().

123 {
124  if (head){
125  iter->next = head->next;
126  return head->info;
127  }
128  return 0;
129 }
listNode * next
Definition: Set.h:22
InfoRecord *const info
Definition: Set.h:15
listNode * next
Definition: Set.h:14
void IRSet::myRemove ( listNode **  n,
InfoRecord r 
)

Definition at line 67 of file Set.C.

References listNode::next.

68 {
69  if ((*n)->info == r)
70  *n = (*n)->next;
71  else
72  myRemove(&((*n)->next), r);
73 }
listNode * next
Definition: Set.h:14
void myRemove(listNode **n, InfoRecord *r)
Definition: Set.C:67
InfoRecord * IRSet::next ( Iterator iter)

Definition at line 131 of file Set.C.

References listNode::info, listNode::next, and Iterator::next.

Referenced by RefineTorusLB::newRefine(), and Rebalancer::refine().

132 {
133  // std::cout << "set::next: " << iter->next << "\n";
134  if (!iter->next)
135  { return 0;
136  }
137  // std::cout << "set::next: iter->next->info=" << iter->next->info << "\n";
138  InfoRecord *temp = iter->next->info;
139  iter->next = iter->next->next;
140  return temp;
141 }
listNode * next
Definition: Set.h:22
InfoRecord *const info
Definition: Set.h:15
listNode * next
Definition: Set.h:14
int IRSet::numElements ( )

Definition at line 144 of file Set.C.

Referenced by Rebalancer::InitProxyUsage(), Rebalancer::multirefine(), Rebalancer::numAvailable(), Rebalancer::printLoads(), and Rebalancer::printSummary().

145 {
146  return nElements;
147 }
void IRSet::print ( )

Definition at line 154 of file Set.C.

References InfoRecord::Id, listNode::info, iout, listNode::next, and Patch::p.

155 {
156  listNode *p = head;
157  while (p){
158  if ( p->info ) iout << p->info->Id << " ";
159  else iout << "NULL ";
160  p = p->next;
161  }
162 }
Definition: Set.h:12
int Id
Definition: elements.h:16
#define iout
Definition: InfoStream.h:87
InfoRecord *const info
Definition: Set.h:15
listNode * next
Definition: Set.h:14
int IRSet::remove ( InfoRecord r)

Definition at line 75 of file Set.C.

References listNode::info, NAMD_bug(), listNode::next, and Patch::p.

Referenced by Rebalancer::deAssign(), RefineTorusLB::newRefine(), and Rebalancer::refine().

76 {
77 #ifdef DEBUG_IRSET
78  listNode *node = head;
79  int n = 0;
80  while (node) { ++n; node = node->next; }
81  if ( n != nElements ) NAMD_bug("IRSet::remove count");
82 #endif
83 
84  if (!head)
85  return 0;
86 
87  listNode *p = head;
88  listNode *q = p->next;
89 
90  if (p->info == r){
91  head = q;
92  delete p;
93  --nElements;
94  return 1;
95  }
96 
97  while (q){
98  if (q->info == r){
99  p->next = q->next;
100  delete q;
101  --nElements;
102  return 1;
103  }
104  else {
105  p = q;
106  q = q->next;
107  }
108  }
109  return 0;
110 }
Definition: Set.h:12
InfoRecord *const info
Definition: Set.h:15
void NAMD_bug(const char *err_msg)
Definition: common.C:123
listNode * next
Definition: Set.h:14
void IRSet::unchecked_insert ( InfoRecord info)

Definition at line 32 of file Set.C.

References find(), NAMD_bug(), and listNode::next.

Referenced by Rebalancer::assign(), and Rebalancer::Rebalancer().

33 {
34 #ifdef DEBUG_IRSET
35  if (find(info)) NAMD_bug("IRSet::unchecked_insert duplicate");
36 #endif
37  ++nElements;
38  listNode *node = new listNode(info);
39  node->next = head;
40  head = node;
41 #ifdef DEBUG_IRSET
42  int n = 0;
43  while (node) { ++n; node = node->next; }
44  if ( n != nElements ) NAMD_bug("IRSet::unchecked_insert count");
45 #endif
46 }
Definition: Set.h:12
void NAMD_bug(const char *err_msg)
Definition: common.C:123
listNode * next
Definition: Set.h:14
int find(InfoRecord *)
Definition: Set.C:112

The documentation for this class was generated from the following files: