vert-x3 / issues

Apache License 2.0
36 stars 7 forks source link

MultiMap is overriding my entries #549

Closed TatianaBuica closed 3 years ago

TatianaBuica commented 3 years ago

The fact that the index is calculated like this (in CaseInsensitiveHeaders), it overrides my entries.

private static int index(int hash) {
        return hash % 17;
}

It is intended to not allow you to have more than 17 entries and override them? If so, could you please let me know what can I use instead?

vietj commented 3 years ago

@TatianaBuica did you find a bug ? do you have a reproducer ?

TatianaBuica commented 3 years ago

When I am trying to make the following insert into a MultiMap, keys doorsUser and encryptionAlgorithm are always fighting for index 4.

MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("doorsUser", "aa");
form.add("encryptionAlgorithm", "");

The fact that the index is calculated as I mentioned above, it is a bit confusing and I am not sure if this is a bug.

vietj commented 3 years ago

is there a bug ? i.e is data overwritten when you use the MultiMap ?

it's expected to have collision inside the implementation, that's how hash tables work https://en.wikipedia.org/wiki/Hash_table#Collision_resolution

vietj commented 3 years ago

I ran the code you provided:

  public static void main(String[] args) {
    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("doorsUser", "aa");
    form.add("encryptionAlgorithm", "");
    for (Object o : form) {
      System.out.println("o = " + o);
    }
    System.out.println("doorsUser=" + form.get("doorsUser"));
    System.out.println("encryptionAlgorithm=" + form.get("encryptionAlgorithm"));
  }

and I got

o = doorsUser=aa
o = encryptionAlgorithm=
doorsUser=aa
encryptionAlgorithm=