Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving problems: key duplication, incorrect hashmap size change on e… #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kostalski
Copy link

Fixing reported issues in hashmap.c :

Adding simple tests.c file with two tests for covering/explaining reported issues.

@kostalski
Copy link
Author

Hi,
I'm sending pull request with two simple fixes for reported issues:

/* has beed updated and keys are not collidinig any more. */
/* Provided keys colliding_key1, colliding_key2 have to be updated, */
/* so they collide again. */
assert(hashmap_hash_int(hmap, colliding_key2) == colliding_keys_hash);
Copy link

@andreasluca andreasluca Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do I need different colliding keys for different architectures?
If I run this test on an iPhone Simulator it works, if I run it in an Android Simulator it doesn't ("717" works in Android Simulator)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Andreas,

It's problem of big-endianess and some settings for Android NDK.
Functions:

  • unsigned long crc32() line: 149, file: hashmap.c
  • unsigned int hashmap_hash_int() line: 167, file: hashmap.c
    are designed for calculating hash for strings and assume, they are working on lilte-endian platform. They will return different results for big-endian platforms and rather not correct ;)

Android supports little and big endianess. Try to setup to little-endian - it should solve the problem (more info: https://stackoverflow.com/questions/6212951/endianness-of-android-ndk).

hashmap.c Outdated
/* After removing element from hash map there can be need to move back */
/* previously pushed elements - pushed moved forward because key colision. */
void _hashmap_shift_chain_after_remove(hashmap_map *m, char *key, int pos){
unsigned int colliding_hash_val;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable colliding_hash_val is unused.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching it. I've just removed colliding_hash_val with next commit (a8a5769)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants