7 * IoTString wraps the underlying char string.
8 * @author Brian Demsky <bdemsky@uci.edu>
12 inline unsigned int hashCharArray(Array<char> *array) {
13 uint len = array->length();
14 unsigned int hash = 0;
15 for (uint i = 0; i < len; i++) {
16 hash = 31 * hash + array->get(i);
25 unsigned int hashvalue;
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 memcpy(array->internalArray(), _array, len);
41 hashvalue = hashCharArray(array);
44 IoTString(IoTString *string) :
45 array(new Array<char>(string->array)),
46 hashvalue(hashCharArray(array)) {
53 char get(uint i) {return array->get(i);}
56 * Internal method to grab a reference to our char array. Caller
60 Array<char> *internalBytes() { return array; }
63 * Returns a copy of the underlying char string.
66 Array<char> *getBytes() { return new Array<char>(array); }
69 * Returns the length in chars of the IoTString.
72 bool equals(IoTString *str) {
73 uint strlength = str->array->length();
74 uint thislength = array->length();
75 if (strlength != thislength)
78 int result = memcmp(str->array->internalArray(), array->internalArray(), strlength);
82 unsigned int hashValue() { return hashvalue;}
83 int length() { return array->length(); }
84 friend IoTString *IoTString_shallow(Array<char> *_array);
87 inline IoTString *IoTString_shallow(Array<char> *_array) {
88 IoTString *str = new IoTString();
93 inline unsigned int hashString(IoTString *a) {
94 return a->hashValue();
97 inline bool StringEquals(IoTString *a, IoTString *b) {