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