IRSet Class Reference

#include <Set.h>

Inheritance diagram for IRSet:

LargeIRSet List of all members.

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.

00018 {
00019   head = (listNode *) 0;
00020   nElements = 0;
00021 }

IRSet::~IRSet (  ) 

Definition at line 23 of file Set.C.

References listNode::next.

00023               {
00024   // delete all links; don't delete the InfoRecord objects
00025   listNode *tmp;
00026   for (listNode *link = head; link; link = tmp) {
00027     tmp = link->next;
00028     delete link;
00029   }
00030 }


Member Function Documentation

int IRSet::find ( InfoRecord  ) 

Definition at line 112 of file Set.C.

References Patch::p.

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

00113 {
00114   listNode *p = head;
00115   while (p) {
00116     if (p->info == r) return 1;
00117     else p = p->next;
00118   }
00119   return 0;
00120 }

int IRSet::hasElements (  ) 

Definition at line 149 of file Set.C.

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

00150 {
00151   return ! ! head;
00152 }

void IRSet::insert ( InfoRecord  ) 

Definition at line 49 of file Set.C.

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

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

00050 {
00051   if (!find(info))
00052   {
00053     ++nElements;
00054     listNode *node = new listNode(info);
00055     node->next = head;
00056     head = node;
00057 #ifdef DEBUG_IRSET
00058     int n = 0;
00059     while (node) { ++n; node = node->next; }
00060     if ( n != nElements ) NAMD_bug("IRSet::insert count");
00061 #endif
00062   }
00063    
00064 }

InfoRecord * IRSet::iterator ( Iterator  ) 

Definition at line 122 of file Set.C.

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

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

00123 {
00124   if (head){
00125     iter->next = head->next;
00126     return head->info;
00127   }
00128   return 0;
00129 }

void IRSet::myRemove ( listNode **  n,
InfoRecord r 
)

Definition at line 67 of file Set.C.

References listNode::next.

00068 {
00069   if ((*n)->info == r)
00070     *n = (*n)->next;
00071   else 
00072     myRemove(&((*n)->next), r);
00073 }

InfoRecord * IRSet::next ( Iterator  ) 

Definition at line 131 of file Set.C.

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

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

00132 {
00133   //  std::cout << "set::next: " << iter->next << "\n";
00134   if (!iter->next)
00135     { return 0;
00136     }
00137   //  std::cout << "set::next: iter->next->info=" << iter->next->info << "\n";
00138   InfoRecord *temp = iter->next->info;
00139   iter->next = iter->next->next;
00140   return temp;
00141 }

int IRSet::numElements (  ) 

Definition at line 144 of file Set.C.

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

00145 {
00146   return nElements;
00147 }

void IRSet::print (  ) 

Definition at line 154 of file Set.C.

References iout, and Patch::p.

00155 {
00156   listNode *p = head;
00157   while (p){
00158     if ( p->info ) iout << p->info->Id << " ";
00159     else iout << "NULL ";
00160     p = p->next;
00161   }
00162 }

int IRSet::remove ( InfoRecord  ) 

Definition at line 75 of file Set.C.

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

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

00076 {
00077 #ifdef DEBUG_IRSET
00078     listNode *node = head;
00079     int n = 0;
00080     while (node) { ++n; node = node->next; }
00081     if ( n != nElements ) NAMD_bug("IRSet::remove count");
00082 #endif
00083 
00084   if (!head)
00085     return 0;
00086 
00087   listNode *p = head;
00088   listNode *q = p->next;
00089 
00090   if (p->info == r){
00091     head = q;
00092     delete p;
00093     --nElements;
00094     return 1;
00095   }
00096 
00097   while (q){
00098     if (q->info == r){
00099       p->next = q->next;
00100       delete q;
00101       --nElements;
00102       return 1;
00103     }
00104     else {
00105       p = q;
00106       q = q->next;
00107     }
00108   }
00109   return 0;
00110 }

void IRSet::unchecked_insert ( InfoRecord  ) 

Definition at line 32 of file Set.C.

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

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

00033 {
00034 #ifdef DEBUG_IRSET
00035   if (find(info)) NAMD_bug("IRSet::unchecked_insert duplicate");
00036 #endif
00037     ++nElements;
00038     listNode *node = new listNode(info);
00039     node->next = head;
00040     head = node;
00041 #ifdef DEBUG_IRSET
00042   int n = 0;
00043   while (node) { ++n; node = node->next; }
00044   if ( n != nElements ) NAMD_bug("IRSet::unchecked_insert count");
00045 #endif
00046 }


The documentation for this class was generated from the following files:
Generated on Sat Sep 23 01:17:19 2017 for NAMD by  doxygen 1.4.7