00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef _intVec_h
00043 #ifdef __GNUG__
00044 #pragma interface
00045 #endif
00046 #define _intVec_h 1
00047
00048 #include "builtin.h"
00049 #include "int.defs.h"
00050
00051 #ifndef _int_typedefs
00052 #define _int_typedefs 1
00053 typedef void (*intProcedure)(int );
00054 typedef int (*intMapper)(int );
00055 typedef int (*intCombiner)(int , int );
00056 typedef int (*intPredicate)(int );
00057 typedef int (*intComparator)(int , int );
00058 #endif
00059
00060
00061 class intVec
00062 {
00063 protected:
00064 int len;
00065 int *s;
00066
00067 intVec(int l, int* d);
00068 public:
00069 intVec ();
00070 intVec (int l);
00071 intVec (int l, int fill_value);
00072 intVec (const intVec&);
00073 ~intVec ();
00074
00075 intVec & operator = (const intVec & a);
00076 intVec at(int from = 0, int n = -1);
00077
00078 int capacity() const;
00079 void resize(int newlen);
00080
00081 int& operator [] (int n);
00082 int& elem(int n);
00083
00084 friend intVec concat(intVec & a, intVec & b);
00085 friend intVec map(intMapper f, intVec & a);
00086 friend intVec merge(intVec & a, intVec & b, intComparator f);
00087 friend intVec combine(intCombiner f, intVec & a, intVec & b);
00088 friend intVec reverse(intVec & a);
00089
00090 void reverse();
00091 void sort(intComparator f);
00092 void fill(int val, int from = 0, int n = -1);
00093
00094 void apply(intProcedure f);
00095 int reduce(intCombiner f, int base);
00096 int index(int targ);
00097
00098 friend int operator == (intVec& a, intVec& b);
00099 friend int operator != (intVec& a, intVec& b);
00100
00101 void error(const char* msg);
00102 void range_error();
00103 };
00104
00105 extern void default_intVec_error_handler(const char*);
00106 extern one_arg_error_handler_t intVec_error_handler;
00107
00108 extern one_arg_error_handler_t
00109 set_intVec_error_handler(one_arg_error_handler_t f);
00110
00111
00112 inline intVec::intVec()
00113 {
00114 len = 0; s = 0;
00115 }
00116
00117 inline intVec::intVec(int l)
00118 {
00119 s = new int [len = l];
00120 }
00121
00122
00123 inline intVec::intVec(int l, int* d) :len(l), s(d) {}
00124
00125
00126 inline intVec::~intVec()
00127 {
00128 delete [] s;
00129 }
00130
00131
00132 inline int& intVec::operator [] (int n)
00133 {
00134 if ((unsigned)n >= (unsigned)len)
00135 range_error();
00136 return s[n];
00137 }
00138
00139 inline int& intVec::elem(int n)
00140 {
00141 return s[n];
00142 }
00143
00144
00145 inline int intVec::capacity() const
00146 {
00147 return len;
00148 }
00149
00150
00151
00152 inline int operator != (intVec& a, intVec& b)
00153 {
00154 return !(a == b);
00155 }
00156
00157 #endif