Stable 31-bit hash so model-keyed advisory lock ids don't overflow int4.
(s: string)
| 574 | |
| 575 | /** Stable 31-bit hash so model-keyed advisory lock ids don't overflow int4. */ |
| 576 | function hashStringToInt32(s: string): number { |
| 577 | let h = 0 |
| 578 | for (let i = 0; i < s.length; i++) { |
| 579 | h = (h * 31 + s.charCodeAt(i)) | 0 |
| 580 | } |
| 581 | return Math.abs(h) % 0x40000000 |
| 582 | } |