samchon / tstl

TypeScript-STL (Standard Template Library, migrated from C++)
MIT License
602 stars 49 forks source link

Improve performance of HashBuckets using bit operation #84

Open samchon opened 3 years ago

samchon commented 3 years ago

Change the hash buckets not to using the mod (%) operator but the bitwise and (&) operator . If size of the hash buckets always be multiple of 2, the ^ operation can replace the % operation and it can reduce elapsed time about 10 percent.

Modulo and Division vs Bitwise Operations

https://mziccard.me/2015/05/08/modulo-and-division-vs-bitwise-operations/