Changeset 12392


Ignore:
Timestamp:
05/19/15 12:54:14 (4 years ago)
Author:
bburlacu
Message:

#2386: Updated GetHashCode method in the EnumerableBoolEqualityComparer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EnumerableBoolEqualityComparer.cs

    r12012 r12392  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    3029    }
    3130    public int GetHashCode(IEnumerable<bool> obj) {
    32       int hash = 0;
    33       int word = 1;
    34       foreach (bool bit in obj) {
    35         // load bits into an integer
    36         word <<= 1;
    37         word |= Convert.ToInt32(bit);
    38         // only happens when the leading 1 reaches the sign bit
    39         if (word < 0) {
    40           // combine word into the hash
    41           hash ^= word;
    42           word = 1;
     31      unchecked {
     32        int hash = 17;
     33        foreach (var bit in obj) {
     34          hash = hash * 29 + (bit ? 1231 : 1237);
    4335        }
     36        return hash;
    4437      }
    45       // combine in any remaining content
    46       if (word > 1) {
    47         hash ^= word;
    48       }
    49       return hash;
    5038    }
    5139  }
Note: See TracChangeset for help on using the changeset viewer.