// File: rb_support.cpp // Author: Karl Abrahamson #include using namespace std; /************************************************ * duplicateString * ************************************************ * duplicateString(s) returns a copy of string * * s, stored in memory allocated using 'new'. * ************************************************/ char* duplicateString(const char* name) { char* buff = new char[strlen(name) + 1]; strcpy(buff, name); return buff; } /************************************************ * max * ************************************************ * max(x,y) returns the larger of x and y. * ************************************************/ int max(int x, int y) { if(x > y) return x; else return y; } /************************************************ * strhash * ************************************************ * strhash(str) is a hash function suitable * * for a hash table whose keys are strings. * ************************************************/ long strhash(const char* str) { long len = strlen(str); long i; long h = 0; for(i = 0; i < len; i++) { long g; h = (h << 4) + (int) str[i]; g = h & 0xF0000000L; if(g != 0) h = h ^ (g >> 24); h = h & ~g; } return h; }