Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

intVec Class Reference

#include <int.Vec.h>

Inheritance diagram for intVec:

Inheritance graph
[legend]
Collaboration diagram for intVec:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 intVec ()
 intVec (int l)
 intVec (int l, int fill_value)
 intVec (const intVec &)
 ~intVec ()
intVecoperator= (const intVec &a)
intVec at (int from=0, int n=-1)
int capacity () const
void resize (int newlen)
int & operator[] (int n)
int & elem (int n)
void reverse ()
void sort (intComparator f)
void fill (int val, int from=0, int n=-1)
void apply (intProcedure f)
int reduce (intCombiner f, int base)
int index (int targ)
void error (const char *msg)
void range_error ()

Protected Member Functions

 intVec (int l, int *d)

Protected Attributes

int len
int * s

Friends

intVec concat (intVec &a, intVec &b)
intVec map (intMapper f, intVec &a)
intVec merge (intVec &a, intVec &b, intComparator f)
intVec combine (intCombiner f, intVec &a, intVec &b)
intVec reverse (intVec &a)
int operator== (intVec &a, intVec &b)
int operator!= (intVec &a, intVec &b)

Constructor & Destructor Documentation

intVec::intVec int  l,
int *  d
[inline, protected]
 

Definition at line 101 of file int.Vec.h.

References len.

00101 :len(l), s(d) {}

intVec::intVec  )  [inline]
 

Definition at line 90 of file int.Vec.h.

References len, and s.

Referenced by at().

00091 {
00092   len = 0; s = 0;
00093 }

intVec::intVec int  l  )  [inline]
 

Definition at line 95 of file int.Vec.h.

References len, and s.

00096 {
00097   s = new int [len = l];
00098 }

intVec::intVec int  l,
int  fill_value
 

Definition at line 69 of file int.Vec.cc.

References len, len, and s.

00070 {
00071   s = new int [len = l];
00072   int* top = &(s[len]);
00073   int* t = s;
00074   while (t < top) *t++ = fill_value;
00075 }

intVec::intVec const intVec  ) 
 

Definition at line 60 of file int.Vec.cc.

References len, len, and s.

00061 {
00062   s = new int [len = v.len];
00063   int* top = &(s[len]);
00064   int* t = s;
00065   const int* u = v.s;
00066   while (t < top) *t++ = *u++;
00067 }

intVec::~intVec  )  [inline]
 

Definition at line 104 of file int.Vec.h.

References s.

00105 {
00106   delete [] s;
00107 }


Member Function Documentation

void intVec::apply intProcedure  f  ) 
 

Definition at line 92 of file int.Vec.cc.

References len, and s.

00093 {
00094   int* top = &(s[len]);
00095   int* t = s;
00096   while (t < top) (*f)(*t++);
00097 }

intVec intVec::at int  from = 0,
int  n = -1
 

Definition at line 222 of file int.Vec.cc.

References intVec(), len, range_error(), and s.

00223 {
00224   int to;
00225   if (n < 0)
00226   {
00227     n = len - from;
00228     to = len - 1;
00229   }
00230   else
00231     to = from + n - 1;
00232   if ((unsigned)from > (unsigned)to)
00233     range_error();
00234   int* news = new int [n];
00235   int* p = news;
00236   int* t = &(s[from]);
00237   int* top = &(s[to]);
00238   while (t <= top) *p++ = *t++;
00239   return intVec(n, news);
00240 }

Here is the call graph for this function:

int intVec::capacity  )  const [inline]
 

Definition at line 123 of file int.Vec.h.

References len.

00124 {
00125   return len;
00126 }

int & intVec::elem int  n  )  [inline]
 

Definition at line 117 of file int.Vec.h.

References s.

00118 {
00119   return s[n];
00120 }

void intVec::error const char *  msg  ) 
 

Definition at line 50 of file int.Vec.cc.

00051 {
00052   (*intVec_error_handler)(msg);
00053 }

void intVec::fill int  val,
int  from = 0,
int  n = -1
 

Definition at line 208 of file int.Vec.cc.

References len, range_error(), and s.

00209 {
00210   int to;
00211   if (n < 0)
00212     to = len - 1;
00213   else
00214     to = from + n - 1;
00215   if ((unsigned)from > (unsigned)to)
00216     range_error();
00217   int* t = &(s[from]);
00218   int* top = &(s[to]);
00219   while (t <= top) *t++ = val;
00220 }

Here is the call graph for this function:

int intVec::index int  targ  ) 
 

Definition at line 181 of file int.Vec.cc.

References intEQ, len, and s.

00182 {
00183   for (int i = 0; i < len; ++i) if (intEQ(targ, s[i])) return i;
00184   return -1;
00185 }

intVec & intVec::operator= const intVec a  ) 
 

Definition at line 78 of file int.Vec.cc.

References len, len, and s.

00079 {
00080   if (this != &v)
00081   {
00082     delete [] s;
00083     s = new int [len = v.len];
00084     int* top = &(s[len]);
00085     int* t = s;
00086     const int* u = v.s;
00087     while (t < top) *t++ = *u++;
00088   }
00089   return *this;
00090 }

int & intVec::operator[] int  n  )  [inline]
 

Reimplemented in intRVec.

Definition at line 110 of file int.Vec.h.

References len, range_error(), and s.

00111 {
00112   if ((unsigned)n >= (unsigned)len)
00113     range_error();
00114   return s[n];
00115 }

Here is the call graph for this function:

void intVec::range_error  ) 
 

Definition at line 55 of file int.Vec.cc.

Referenced by at(), fill(), operator[](), and intRVec::operator[]().

00056 {
00057   (*intVec_error_handler)("Index out of range.");
00058 }

int intVec::reduce intCombiner  f,
int  base
 

Definition at line 140 of file int.Vec.cc.

References len, and s.

00141 {
00142   int r = base;
00143   int* top = &(s[len]);
00144   int* t = s;
00145   while (t < top) r = (*f)(r, *t++);
00146   return r;
00147 }

void intVec::resize int  newlen  ) 
 

Definition at line 100 of file int.Vec.cc.

References len, and s.

Referenced by intRVec::grow().

00101 {
00102   int* news = new int [newl];
00103   int* p = news;
00104   int minl = (len < newl)? len : newl;
00105   int* top = &(s[minl]);
00106   int* t = s;
00107   while (t < top) *p++ = *t++;
00108   delete [] s;
00109   s = news;
00110   len = newl;
00111 }

void intVec::reverse  ) 
 

Definition at line 166 of file int.Vec.cc.

References len, and s.

00167 {
00168   if (len != 0)
00169   {
00170     int* lo = s;
00171     int* hi = &(s[len - 1]);
00172     while (lo < hi)
00173     {
00174       int tmp = *lo;
00175       *lo++ = *hi;
00176       *hi-- = tmp;
00177     }
00178   }
00179 }

void intVec::sort intComparator  f  ) 
 

Definition at line 274 of file int.Vec.cc.

References gsort(), len, and s.

00275 {
00276   gsort(s, len, compar);
00277 }

Here is the call graph for this function:


Friends And Related Function Documentation

intVec combine intCombiner  f,
intVec a,
intVec b
[friend]
 

Definition at line 128 of file int.Vec.cc.

00129 {
00130   int newl = (a.len < b.len)? a.len : b.len;
00131   int* news = new int [newl];
00132   int* p = news;
00133   int* top = &(a.s[newl]);
00134   int* t = a.s;
00135   int* u = b.s;
00136   while (t < top) *p++ = (*f)(*t++, *u++);
00137   return intVec(newl, news);
00138 }

intVec concat intVec a,
intVec b
[friend]
 

Definition at line 113 of file int.Vec.cc.

00114 {
00115   int newl = a.len + b.len;
00116   int* news = new int [newl];
00117   int* p = news;
00118   int* top = &(a.s[a.len]);
00119   int* t = a.s;
00120   while (t < top) *p++ = *t++;
00121   top = &(b.s[b.len]);
00122   t = b.s;
00123   while (t < top) *p++ = *t++;
00124   return intVec(newl, news);
00125 }

intVec map intMapper  f,
intVec a
[friend]
 

Definition at line 187 of file int.Vec.cc.

00188 {
00189   int* news = new int [a.len];
00190   int* p = news;
00191   int* top = &(a.s[a.len]);
00192   int* t = a.s;
00193   while(t < top) *p++ = (*f)(*t++);
00194   return intVec(a.len, news);
00195 }

intVec merge intVec a,
intVec b,
intComparator  f
[friend]
 

Definition at line 242 of file int.Vec.cc.

00243 {
00244   int newl = a.len + b.len;
00245   int* news = new int [newl];
00246   int* p = news;
00247   int* topa = &(a.s[a.len]);
00248   int* as = a.s;
00249   int* topb = &(b.s[b.len]);
00250   int* bs = b.s;
00251 
00252   for (;;)
00253   {
00254     if (as >= topa)
00255     {
00256       while (bs < topb) *p++ = *bs++;
00257       break;
00258     }
00259     else if (bs >= topb)
00260     {
00261       while (as < topa) *p++ = *as++;
00262       break;
00263     }
00264     else if ((*f)(*as, *bs) <= 0)
00265       *p++ = *as++;
00266     else
00267       *p++ = *bs++;
00268   }
00269   return intVec(newl, news);
00270 }

int operator!= intVec a,
intVec b
[friend]
 

Definition at line 130 of file int.Vec.h.

00131 {
00132   return !(a == b);
00133 }

int operator== intVec a,
intVec b
[friend]
 

Definition at line 197 of file int.Vec.cc.

00198 {
00199   if (a.len != b.len)
00200     return 0;
00201   int* top = &(a.s[a.len]);
00202   int* t = a.s;
00203   int* u = b.s;
00204   while (t < top) if (!(intEQ(*t++, *u++))) return 0;
00205   return 1;
00206 }

intVec reverse intVec a  )  [friend]
 

Definition at line 149 of file int.Vec.cc.

00150 {
00151   int* news = new int [a.len];
00152   if (a.len != 0)
00153   {
00154     int* lo = news;
00155     int* hi = &(news[a.len - 1]);
00156     while (lo < hi)
00157     {
00158       int tmp = *lo;
00159       *lo++ = *hi;
00160       *hi-- = tmp;
00161     }
00162   }
00163   return intVec(a.len, news);
00164 }


Member Data Documentation

int intVec::len [protected]
 

Definition at line 42 of file int.Vec.h.

Referenced by apply(), at(), capacity(), combine(), concat(), fill(), intRVec::grow(), index(), intVec(), map(), merge(), operator=(), operator==(), operator[](), intRVec::operator[](), reduce(), resize(), reverse(), reverse(), sort(), and intRVec::viable_range().

int* intVec::s [protected]
 

Definition at line 43 of file int.Vec.h.

Referenced by apply(), at(), combine(), concat(), elem(), fill(), intRVec::grow(), index(), intVec(), map(), merge(), operator=(), operator==(), operator[](), intRVec::operator[](), reduce(), resize(), reverse(), sort(), and ~intVec().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:53:44 2004 for NS2.26SourcesOriginal by doxygen 1.3.3