diff --git a/src/engine/engine_support.c b/src/engine/engine_support.c index c3601931..5deb1e72 100644 --- a/src/engine/engine_support.c +++ b/src/engine/engine_support.c @@ -1050,11 +1050,11 @@ static int _getnumadr(const mjModel* m, mjtObj type, int** padr, int* mapadr) { } // get string hash, see http://www.cse.yorku.ca/~oz/hash.html -uint64_t mj_hashdjb2(const char* s, uint64_t n) { +uint64_t mj_hashString(const char* s, uint64_t n) { uint64_t h = 5381; int c; while ((c = *s++)) { - h = ((h << 5) + h) + c; + h = ((h << 5) + h) ^ c; } return h % n; } @@ -1070,7 +1070,7 @@ int mj_name2id(const mjModel* m, int type, const char* name) { // search if (num) { // look up at hash address - uint64_t hash = mj_hashdjb2(name, num); + uint64_t hash = mj_hashString(name, num); uint64_t i = hash; do { diff --git a/src/engine/engine_support.h b/src/engine/engine_support.h index 122c59ba..a5d3c7ae 100644 --- a/src/engine/engine_support.h +++ b/src/engine/engine_support.h @@ -114,7 +114,7 @@ MJAPI void mj_angmomMat(const mjModel* m, mjData* d, mjtNum* mat, int body); //-------------------------- name functions -------------------------------------------------------- // get string hash, see http://www.cse.yorku.ca/~oz/hash.html -uint64_t mj_hashdjb2(const char* s, uint64_t n); +uint64_t mj_hashString(const char* s, uint64_t n); // get id of object with the specified mjtObj type and name, returns -1 if id not found MJAPI int mj_name2id(const mjModel* m, int type, const char* name); diff --git a/src/user/user_model.cc b/src/user/user_model.cc index d8a72c50..c160a8a0 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -1492,7 +1492,7 @@ static int namelist(vector& list, int adr, int* name_adr, char* names, int* continue; } - uint64_t j = mj_hashdjb2(list[i]->name.c_str(), map_size); + uint64_t j = mj_hashString(list[i]->name.c_str(), map_size); // find first empty slot using linear probing for (; map[j]!=-1; j=(j+1) % map_size) {}