I looked at a lot of questions here in the PHP Integer Overflow section, but I can't find anything that answers my specific question, so I hope I haven't missed the existing answer.
I want to use djb2 โโhash in PHP for hash keys in something like a fragment identifier (domain index for SimpleDB). It overflows the unsigned long int, so I cannot do it the same way in direct PHP, because the native int int PHPs are 32-bit.
So, I tried PHP bc and libgmp mathematical extensions that allow arbitrary lengths and they bypass the signature / scale problem, but they make ints "too big", that is, they do not overflow.
Using GMP in particular works and seems to give consistent results, but obviously an order of magnitude slower than in C (0m0.017s vs 0m0.002s). I do not know if this is simply because it is PHP versus C, or would it be much faster in PHP if I could overwhelm it. I would rather check and find out, but I see no way to do this.
So, is there a way to force ULONG to maximum in PHP? Maybe I have to wrap the C function in a PHP extension? Or, given that I only plan to hash short characters (maybe 64 characters or less), will this provide a significant reduction in return?
, - 32 ? long , >= 32 . 32- long 32 .
long
, , , , 64 , , , long long ( >= 64 32- ), , .
long long
"djb2" - -, , . modulo , "modulo 2^(sizeof long)". ( ) , C, , , -. PHP, double .
modulo 2^(sizeof long)
double
PHP, , , PHP_INT_MAX ( 64- PHP, ?). , (33) , , .
PHP_INT_MAX
Source: https://habr.com/ru/post/1783926/More articles:Using Microsoft DTV-DVD Video Decoder to Play H264 Video - filterphp url-routing - phpHow to capture link header + images when sharing - phphttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1783924/intercepting-keyevents-to-mediacontroller&usg=ALkJrhix1PMvY66L_IBpw_fSQ_IewyMugQWhat is the best way to store geographic information regarding db? - databaseSharePointSelect a query for duplicate dates with a tolling table - sqlAlternative overflow-y in CSS? - cssLinearLayout - How to get text to the right of the icon? - androidHow to exclude specific folders when copying using MSBUILD - buildAll Articles