/* $Id: array.cpp,v 1.0 2003/04/21 17:45:48 folkert Exp folkert $ * $Log: array.cpp,v $ * Revision 1.0 2003/04/21 17:45:48 folkert * small fixes * * Revision 0.95 2003/03/16 14:12:40 folkert * *** empty log message *** * * Revision 0.8 2003/02/20 19:23:36 folkert * *** empty log message *** * * Revision 0.6 2003/02/04 21:26:09 folkert * fixed some bugs * made strings case-insenstive * * Revision 0.5 2003/02/03 19:48:55 folkert * *** empty log message *** * */ #include "array.h" #include #include #include #include #include #include "main.h" extern "C" { #include "mem.h" } array::array(int numberofcounters, int n_subs) { assert(numberofcounters >= 1); subarrays = NULL; nsubarrays = n_subs; counters = NULL; ncounters = numberofcounters; strings = NULL; nin = 0; } array::~array() { if (counters) free(counters); if (strings) free(strings); } void array::setcounter(int index, int subindex, int value) { counters[(index * ncounters) + subindex] = value; } int array::addcounter(int index, int subindex, int value) { return counters[(index * ncounters) + subindex] += value; } int array::getcounter(int index, int subindex) { return counters[(index * ncounters) + subindex]; } char * get_email_address(char *in) { char *out; char *l = strchr(in, '<'); if (!l) { char *space = strchr(in, ' '); if (space) *space = 0x00; return strdup(in); } out = strdup(l + 1); char *r = strchr(out, '>'); if (r) *r = 0x00; return out; } int array::addstring(char *string, char isemail) { int loop, len=strlen(string); /* make lowercase */ for(loop=0; loop begin) { int pivot = getcounter(begin, subindex); int l = begin + 1; int r = end; while(l < r) { if (getcounter(l, subindex) > pivot) l++; else { r--; swap_entry(l, r); } } l--; swap_entry(begin, l); quicksort(subindex, begin, l); quicksort(subindex, r, end); } } void array::swap_entry(int index1, int index2) { char *dummy = strings[index1]; strings[index1] = strings[index2]; strings[index2] = dummy; if (index1 < 0 || index2 < 0) { fprintf(stderr, "\nswap_entry: %d %d\n", index1, index2); exit(1); } for(int loop=0; loop=nin) return NULL; else return strings[index]; }