8 * IoTString wraps the underlying char string.
9 * @author Brian Demsky <bdemsky@uci.edu>
13 inline unsigned int hashCharArray(Array<char> *array) {
14 uint len = array->length();
15 unsigned int hash = 0;
16 for (uint i = 0; i < len; i++) {
17 hash = 31 * hash + ((unsigned int) array->get(i));
26 unsigned int hashvalue;
28 * Builds an IoTString object around the char array. This
29 * constructor makes a copy, so the caller is free to modify the char array.
33 IoTString(Array<char> *_array) :
34 array(new Array<char>(_array)),
35 hashvalue(hashCharArray(array)) {
38 IoTString(const char *_array) {
39 int32_t len = strlen(_array);
40 array = new Array<char>(len);
41 memcpy(array->internalArray(), _array, len);
42 hashvalue = hashCharArray(array);
45 IoTString(IoTString *string) :
46 array(new Array<char>(string->array)),
47 hashvalue(string->hashvalue) {
55 for(uint i=0; i < array->length(); i++)
56 printf("%c", array->get(i));
59 char get(uint i) {return array->get(i);}
62 * Internal method to grab a reference to our char array. Caller
66 Array<char> *internalBytes() { return array; }
69 * Returns a copy of the underlying char string.
72 Array<char> *getBytes() { return new Array<char>(array); }
75 * Returns the length in chars of the IoTString.
79 bool equals(IoTString *str) {
80 uint strlength = str->array->length();
81 uint thislength = array->length();
82 if (strlength != thislength)
85 int result = memcmp(str->array->internalArray(), array->internalArray(), strlength);
89 unsigned int hashValue() { return hashvalue;}
90 int length() { return array->length(); }
91 friend IoTString *IoTString_shallow(Array<char> *_array);
94 inline IoTString *IoTString_shallow(Array<char> *_array) {
95 IoTString *str = new IoTString();
97 str->hashvalue = hashCharArray(_array);
101 inline unsigned int hashString(IoTString *a) {
102 return a->hashValue();
105 inline bool StringEquals(IoTString *a, IoTString *b) {