7 * IoTString wraps the underlying char string.
8 * @author Brian Demsky <bdemsky@uci.edu>
12 inline int hashCharArray(Array<char> *array) {
13 uint len = array->length();
15 for (uint i = 0; i < len; i++) {
16 hash = 31 * hash + array->get(i);
27 * Builds an IoTString object around the char array. This
28 * constructor makes a copy, so the caller is free to modify the char array.
32 IoTString(Array<char> *_array) :
33 array(new Array<char>(_array)),
34 hashvalue(hashCharArray(array)) {
37 IoTString(const char *_array) {
38 int32_t len = strlen(_array);
39 array = new Array<char>(len);
40 strcpy(array->internalArray(), _array);
41 hashvalue = hashCharArray(array);
44 IoTString(IoTString *string) :
45 array(new Array<char>(string->array)),
46 hashvalue(hashCharArray(array)) {
54 * Internal method to grab a reference to our char array. Caller
58 Array<char> *internalBytes() { return array; }
61 * Returns a copy of the underlying char string.
64 Array<char> *getBytes() { return new Array<char>(array); }
67 * Returns the length in chars of the IoTString.
70 bool equals(IoTString *str) {
71 uint strlength = str->array->length();
72 uint thislength = array->length();
73 if (strlength != thislength)
76 int result = memcmp(str->array->internalArray(), array->internalArray(), strlength);
80 int hashValue() { return hashvalue;}
81 int length() { return array->length(); }
82 friend IoTString *IoTString_shallow(Array<char> *_array);
85 inline IoTString *IoTString_shallow(Array<char> *_array) {
86 IoTString *str = new IoTString();
91 inline int hashString(IoTString *a) {
92 return a->hashValue();
95 inline bool StringEquals(IoTString *a, IoTString *b) {