experimenting with a more general way of hashing a namespace, for future javascript golf. the idea is that existing browser objects can be hashed so that wasteful strings like createDocumentFragment
can be avoided entirely, and keys from several objects (such as document
, window
, String
, etc.) can be hashed into one namespace.
for example:
d = document
d.body.appendChild(d.createElement("script")).src="URL"
could be shortened to
d = document
d[rk][XU](d[Ou]("script")).src="URL"
this specific approach takes every key on the document, turns it into a large number by multiplying each codepoint with an index and then summing and modding by 3456 (54 * 64), which is the maximum number of items representable with a two-byte javascript identifier:
/[a-z_$][0-9a-z_$]/i
this yields decent results. in an empty chrome page, there were only 3 collisions. the idea is that the upper bound can be lowered as necessary, until the collisions are acceptable.
e+=26982<e // skip the "if" keyword :p
Actually, if you wanna go the "skip keywords" road, the modulo should be applied after the "skips", or the "skips" should be applied inside the loop computing
e
which would allow us to keep the modulo at 3456