refactor: Replace hash code magic number with named constant
Add HashMultiplier constant to BinComparer, BinItem, MultiBin, and Tool Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,23 +36,25 @@ namespace CutList.Core
|
|||||||
|
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
|
// Prime multiplier reduces collisions in hash-based collections
|
||||||
|
const int HashMultiplier = 23;
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 23 + bin.Length.GetHashCode();
|
hash = hash * HashMultiplier + bin.Length.GetHashCode();
|
||||||
hash = hash * 23 + bin.Spacing.GetHashCode();
|
hash = hash * HashMultiplier + bin.Spacing.GetHashCode();
|
||||||
hash = hash * 23 + bin.Items.Count.GetHashCode();
|
hash = hash * HashMultiplier + bin.Items.Count.GetHashCode();
|
||||||
|
|
||||||
// Include first and last item in hash for better distribution
|
// Include first and last item in hash for better distribution
|
||||||
if (bin.Items.Count > 0)
|
if (bin.Items.Count > 0)
|
||||||
{
|
{
|
||||||
var firstItem = bin.Items[0];
|
var firstItem = bin.Items[0];
|
||||||
hash = hash * 23 + (firstItem.Name?.GetHashCode() ?? 0);
|
hash = hash * HashMultiplier + (firstItem.Name?.GetHashCode() ?? 0);
|
||||||
hash = hash * 23 + firstItem.Length.GetHashCode();
|
hash = hash * HashMultiplier + firstItem.Length.GetHashCode();
|
||||||
|
|
||||||
if (bin.Items.Count > 1)
|
if (bin.Items.Count > 1)
|
||||||
{
|
{
|
||||||
var lastItem = bin.Items[bin.Items.Count - 1];
|
var lastItem = bin.Items[bin.Items.Count - 1];
|
||||||
hash = hash * 23 + (lastItem.Name?.GetHashCode() ?? 0);
|
hash = hash * HashMultiplier + (lastItem.Name?.GetHashCode() ?? 0);
|
||||||
hash = hash * 23 + lastItem.Length.GetHashCode();
|
hash = hash * HashMultiplier + lastItem.Length.GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,9 +77,11 @@
|
|||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
|
// Prime multiplier reduces collisions in hash-based collections
|
||||||
|
const int HashMultiplier = 23;
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 23 + (Name?.GetHashCode() ?? 0);
|
hash = hash * HashMultiplier + (Name?.GetHashCode() ?? 0);
|
||||||
hash = hash * 23 + Length.GetHashCode();
|
hash = hash * HashMultiplier + Length.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,10 +112,12 @@
|
|||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
|
// Prime multiplier reduces collisions in hash-based collections
|
||||||
|
const int HashMultiplier = 23;
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 23 + Quantity.GetHashCode();
|
hash = hash * HashMultiplier + Quantity.GetHashCode();
|
||||||
hash = hash * 23 + Length.GetHashCode();
|
hash = hash * HashMultiplier + Length.GetHashCode();
|
||||||
hash = hash * 23 + Priority.GetHashCode();
|
hash = hash * HashMultiplier + Priority.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,10 +96,12 @@
|
|||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
|
// Prime multiplier reduces collisions in hash-based collections
|
||||||
|
const int HashMultiplier = 23;
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 23 + (Name?.GetHashCode() ?? 0);
|
hash = hash * HashMultiplier + (Name?.GetHashCode() ?? 0);
|
||||||
hash = hash * 23 + Kerf.GetHashCode();
|
hash = hash * HashMultiplier + Kerf.GetHashCode();
|
||||||
hash = hash * 23 + AllowUserToChange.GetHashCode();
|
hash = hash * HashMultiplier + AllowUserToChange.GetHashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user