HashedString.cpp 707 B

1234567891011121314151617181920212223242526272829
  1. #include "common/utils/HashedString.h"
  2. HashedString::HashedString() : length(0), hash(0) {
  3. data[length] = '\0';
  4. }
  5. HashedString::HashedString(const char* str) : length(0), hash(0) {
  6. for(; length < LENGTH - 1 && str[length] != '\0'; length++) {
  7. data[length] = str[length];
  8. hash = hash * 257 + str[length];
  9. }
  10. data[length] = '\0';
  11. }
  12. bool HashedString::operator==(const HashedString& other) const {
  13. return hash == other.hash && length == other.length;
  14. }
  15. bool HashedString::operator!=(const HashedString& other) const {
  16. return !(*this == other);
  17. }
  18. HashedString::operator const char*() const {
  19. return data;
  20. }
  21. u32 HashedString::hashCode() const {
  22. return hash;
  23. }