1 #ifndef __LOUT_MISC_HH__
2 #define __LOUT_MISC_HH__
19 template <
class T>
inline T
min (T a, T b) {
return a < b ? a : b; }
20 template <
class T>
inline T
max (T a, T b) {
return a > b ? a : b; }
22 template <
class T>
inline T
min (T a, T b, T c)
24 return (
min (a,
min (b, c)));
26 template <
class T>
inline T
max (T a, T b, T c)
28 return (
max (a,
max (b, c)));
33 void init (
int argc,
char *argv[]);
37 fprintf (stderr,
"*** [%s] This should not happen! ***\n",
prgName);
43 return (
int) ((d > 0) ? (d + 0.5) : (d - 0.5));
48 return ((c >=
'A' && c <=
'Z') ? c + 0x20 : c);
53 return ((c >=
'a' && c <=
'z') ? c - 0x20 : c);
93 static int compareFun(
const void *p1,
const void *p2);
113 this->
array = (T*) malloc (
sizeof (T));
115 if (this->numAlloc < this->
num) {
116 this->
numAlloc = (this->num < 100) ?
117 this->num : this->num + this->num/10;
173 assert (newSize >= 0);
184 int oldSize = this->
num;
186 for (
int i = oldSize; i < newSize; i++)
196 assert (i >= 0 && this->
num - i > 0);
206 inline T
get (
int i) {
207 assert (i >= 0 && this->
num - i > 0);
208 return this->
array[i];
215 assert (this->
num > 0);
223 assert (this->
num > 0);
224 return this->
array[0];
231 assert (this->
num > 0);
239 assert (this->
num > 0);
251 inline void set (
int i, T t) {
252 assert (i >= 0 && this->
num - i > 0);
304 this->
arrayMain = (T*) malloc (
sizeof (T));
306 if (this->numAllocMain < this->
numMain) {
308 this->numMain : this->numMain + this->numMain/10;
324 if (this->numAllocExtra < this->
numExtra) {
326 this->numExtra : this->numExtra + this->numExtra/10;
365 this->arrayExtra = NULL;
369 memcpy (this->arrayExtra, o.arrayExtra, sizeof (T) *
numExtra);
390 assert (newSize >= 0);
397 assert (numInsert >= 0);
413 insert (index, numInsert);
419 int toMove =
startExtra + oldNumExtra - index;
422 toMove *
sizeof (T));
430 int diff = index - this->
startExtra - oldNumExtra;
432 for (
int i = diff + oldNumExtra - 1; i >= 0; i--) {
433 T *src = i < oldNumExtra ?
434 this->
arrayExtra1 + i : arrayMainI + (i - oldNumExtra);
441 startExtra = index - oldNumExtra;
458 else if (i >= this->startExtra + this->
numExtra)
473 return *(this->
getRef(i));
480 assert (
size () > 0);
495 assert (
size () > 0);
514 inline void set (
int i, T t) {
569 void set(
int i,
bool val);
624 for (
int i = 0; i <
bulk->
size (); i++)
630 inline const char *
strndup (
const char *str,
size_t t) {
631 char *new_str = (
char *)
zoneAlloc (t + 1);
632 memcpy (new_str, str, t);
637 inline const char *
strdup (
const char *str) {
638 return strndup (str, strlen (str));
646 #endif // __LOUT_MISC_HH__