Created
October 1, 2020 17:18
-
-
Save cevek/7d08145d1c6becdb1764fdaa60622553 to your computer and use it in GitHub Desktop.
Fast binary switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function id8(p) { | |
if (p > 3) { | |
if (p > 5) { | |
if (p === 6) { | |
return 6; | |
} else { | |
return 7; | |
} | |
} else { | |
if (p === 4) { | |
return 4; | |
} else { | |
return 5; | |
} | |
} | |
} else { | |
if (p > 1) { | |
if (p === 2) { | |
return 2; | |
} else { | |
return 3; | |
} | |
} else { | |
if (p === 1) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
} | |
} | |
function id16(p) { | |
if (p > 7) { | |
if (p > 11) { | |
if (p > 13) { | |
if (p === 14) { | |
return 14; | |
} else { | |
return 15; | |
} | |
} else { | |
if (p === 12) { | |
return 12; | |
} else { | |
return 13; | |
} | |
} | |
} else { | |
if (p > 9) { | |
if (p === 10) { | |
return 10; | |
} else { | |
return 11; | |
} | |
} else { | |
if (p === 9) { | |
return 9; | |
} else { | |
return 8; | |
} | |
} | |
} | |
} else { | |
if (p > 3) { | |
if (p > 5) { | |
if (p === 6) { | |
return 6; | |
} else { | |
return 7; | |
} | |
} else { | |
if (p === 4) { | |
return 4; | |
} else { | |
return 5; | |
} | |
} | |
} else { | |
if (p > 1) { | |
if (p === 2) { | |
return 2; | |
} else { | |
return 3; | |
} | |
} else { | |
if (p === 1) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
} | |
} | |
} | |
function id32(p) { | |
if (p > 15) { | |
if (p > 23) { | |
if (p > 27) { | |
if (p > 29) { | |
if (p === 30) { | |
return 30; | |
} else { | |
return 31; | |
} | |
} else { | |
if (p === 28) { | |
return 28; | |
} else { | |
return 29; | |
} | |
} | |
} else { | |
if (p > 25) { | |
if (p === 26) { | |
return 26; | |
} else { | |
return 27; | |
} | |
} else { | |
if (p === 25) { | |
return 25; | |
} else { | |
return 24; | |
} | |
} | |
} | |
} else { | |
if (p > 19) { | |
if (p > 21) { | |
if (p === 22) { | |
return 22; | |
} else { | |
return 23; | |
} | |
} else { | |
if (p === 20) { | |
return 20; | |
} else { | |
return 21; | |
} | |
} | |
} else { | |
if (p > 17) { | |
if (p === 18) { | |
return 18; | |
} else { | |
return 19; | |
} | |
} else { | |
if (p === 16) { | |
return 16; | |
} else { | |
return 17; | |
} | |
} | |
} | |
} | |
} else { | |
if (p > 7) { | |
if (p > 11) { | |
if (p > 13) { | |
if (p === 14) { | |
return 14; | |
} else { | |
return 15; | |
} | |
} else { | |
if (p === 12) { | |
return 12; | |
} else { | |
return 13; | |
} | |
} | |
} else { | |
if (p > 9) { | |
if (p === 10) { | |
return 10; | |
} else { | |
return 11; | |
} | |
} else { | |
if (p === 9) { | |
return 9; | |
} else { | |
return 8; | |
} | |
} | |
} | |
} else { | |
if (p > 3) { | |
if (p > 5) { | |
if (p === 6) { | |
return 6; | |
} else { | |
return 7; | |
} | |
} else { | |
if (p === 4) { | |
return 4; | |
} else { | |
return 5; | |
} | |
} | |
} else { | |
if (p > 1) { | |
if (p === 2) { | |
return 2; | |
} else { | |
return 3; | |
} | |
} else { | |
if (p === 1) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment