Skip to content

Commit

Permalink
Use real hash for badgehue
Browse files Browse the repository at this point in the history
  • Loading branch information
mayfield committed Nov 22, 2023
1 parent 504bf8a commit 1956a03
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pages/src/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,14 +1344,7 @@ export function eventBadge(label) {


export function badgeHue(name) {
name = name || '';
let s = 0;
for (let i = 0; i < name.length; i++) {
s += name.charCodeAt(i)*17*((i % 3)+1); //multiply by 7 times i+1 to create real variance given tight range of charCodes and frequency of team names being small number of characters relative to large range of hues (360)
s = s % 360; //applies mod function to keep s from getting to be a really large number
// should create variance so "OTR DS" and "OTR OF" aren't just 2 hue different, they are quite a bit different. The i % 3 component is important to prevent "AD" from being identical to "BC"
}
return s % 360;
return hash(name) % 360;
}


Expand Down Expand Up @@ -1515,7 +1508,11 @@ export function cyrb53(str, seed=0) {
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
}
export const hash = cyrb53; // simple name is fine when we don't care about the impl


export function hash(str) {
return cyrb53(str || '');
}


export function binarySearchClosest(arr, value) {
Expand Down

0 comments on commit 1956a03

Please sign in to comment.