java - What's a quick hash, which will map UUIDs to the unit interval? -


i'm looking hash uuids unit interval, on hot path application.

this sounds should have been efficiently solved, searches haven't yet turned solution. know of (and have reference sample implementation) quick/efficient hash of uuids unit interval (obviously while preserving of random distribution possible).

this method keeps "uniqueness level" of uuid one-to-one bijection of each large number corresponding float number on interval between [1/maxuuid,1].

after removing hyphens, uuid string simple hex string. convert bigint , divide maximal possible uuid-number(128 bit ff...fff).

string hexuuid = uuidstr.replaceall('-',''); bigdecimal uuid = new bigdecimal(new biginteger(hexuuid , 16)); bigdecimal maximal = new bigdecimal(new biginteger("ffff...ff",16)); // compute once!! bigdecimal floatid = uuid.divide(maximal, mathcontext.decimal128); 

probably, have play characters case (to lowercase before converting number), play big decimal divide parameters (scale, rounding mode) main idea presented in code above.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -