edits
[iotcloud.git] / version2 / src / C / IoTString.h
index 1fb527f03a9977233377a1796c0c2c47e656993c..583a098a07df5aff5f663d4e8299d56c1258497a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "array.h"
 #include <string.h>
+#include <stdio.h>
 /**
  * IoTString wraps the underlying char string.
  * @author Brian Demsky <bdemsky@uci.edu>
@@ -13,7 +14,7 @@ inline unsigned int hashCharArray(Array<char> *array) {
        uint len = array->length();
        unsigned int hash = 0;
        for (uint i = 0; i < len; i++) {
-               hash = 31 * hash + array->get(i);
+               hash = 31 * hash + ((unsigned int) array->get(i));
        }
        return hash;
 }
@@ -42,14 +43,19 @@ public:
        }
 
        IoTString(IoTString *string) :
-               array(new Array<char>(string->array)),
-               hashvalue(hashCharArray(array)) {
+         array(new Array<char>(string->array)),
+               hashvalue(string->hashvalue) {
        }
 
        ~IoTString() {
                delete array;
        }
 
+       void print() {
+               for(uint i=0; i < array->length(); i++)
+                       printf("%c", array->get(i));
+       };
+       
        char get(uint i) {return array->get(i);}
 
        /**
@@ -69,6 +75,7 @@ public:
         * Returns the length in chars of the IoTString.
         */
 
+       
        bool equals(IoTString *str) {
                uint strlength = str->array->length();
                uint thislength = array->length();
@@ -87,6 +94,7 @@ public:
 inline IoTString *IoTString_shallow(Array<char> *_array) {
        IoTString *str = new IoTString();
        str->array = _array;
+       str->hashvalue = hashCharArray(_array);
        return str;
 }