Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1464

Hash Collision on Pair<> with auto-boxing type.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • lang.tuple.*

    Description

      I create 1 million objects with Integer pair. But, the total number of the pair hash kinds is 1024.

          public static void main(String[] args) {
              Set<Integer> set = new TreeSet<>();
              for (int i = 0; i < 1000; i++) {
                  for (int j = 0; j < 1000; j++) {
                      Pair<Integer, Integer> intPair = Pair.of(i, j);
                      set.add(intPair.hashCode());
                  }
              }
      
              System.out.printf("%d", set.size());
          }
      

      I think the Pair.hashCode need to write more complex.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            Morris Yang Shiang-Yun
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: