From: Mitra <mi...@mi...> - 2003-01-25 13:48:03
|
Well spotted! I get similar results (and those two "huh" should be "huhl", 've got Array ( [16] =3D> 3652 [15] =3D> 15 ) packed Array ( [32] =3D> 3652 [30] =3D> 15 ) unpacked - Mitra At 2:43 PM +0100 25/1/03, Honza Malik wrote: >Hi Mitra, > > I did some more testing on ids and now I know, where the problem is. >The new_id() is OK - it returns allways 32 character long id, but >sometimes it return id with ...20 at the end. Packed '20' is space and >this is problem, because if you insert 16 characters long packed id >ending with space into MySQL and then you get it back, the id is 15 >character long. > >MySQL REMOVES ENDING SPACES FROM INSERTED STRING! > >I will fix new_id() to not generate such ids. > > >On P=E1, 2003-01-24 at 12:28, Mitra wrote: >> Ok - stranger .... my guess was wrong, md5 returns a 32 character >> string, which cannot contain 00 or 27 so cannot end up as a shorter >> string. >> >> To test, I ran a loop through 99999 samples of new_id, which should >> have generated about 400 bad ids by your statistics. >> >> I think the bad ids in your database must be the result of some buggy >> earlier code. >> >> Lets try three things. >> 1: Please check my test - appended at the end of this message. > >I test it and all 99999 ids are 32 characters long. > >> 2: Please re-run your test, see if the number of bad ids has gone up, >> if there is something bad then as long as you have created more than >> 256 ids then statistically it should have increased by 1 or more. > >Increased: [16] =3D> 92254 [15] =3D> 367 [14] =3D> 4 > >> 3: Please send the code for your test, I'll run it on my installation >> and see how many odd length ids I have. > >require "include/config.php3"; >require $GLOBALS[AA_INC_PATH]."util.php3"; >require $GLOBALS[AA_INC_PATH]."locsessi.php3"; > >$db =3D new DB_AA; > >$db->query( "SELECT id from item" ); >while($db->next_record()) { > $fromdb[$len_p =3D strlen($db->f('id'))]++; > $unpdb[$len_u =3D strlen(unpack_id($db->f('id')))]++; >// if( $len_p<16 ) >// echo "<br>".$db->f('id'); >} > >huh($fromdb, 'packed'); >huh($unpdb, 'unpacked'); > >echo " > > Regards > Honza "; > > > > > > - Mitra > > > > > > At 11:55 PM +0100 22/1/03, Honza Malik wrote: > > > >3) Your assumption that packed ids are EXACTLY 16 characters long (= and >> > >unpacked are EXACTLY 32 characters long) is unfortunately wrong. I c= an't >> > >say you why - we generate the ids by new_id() function, but in our >> > >database are packed ids for item 16 (in 91907 items), 15 (366) and 1= 4 >> > >(4) characters long. >> > >> > Strange - because new_id uses "md5" which has to return 128 bits. >> > >> > I wonder if these were ids which generated a leading ascii zero, the >> > ratios look reasonable for this, i.e. 919007/366 =3D 251, which is >> > close to a one in 256 chance, i.e. something that occurred when 8 >> > bits (2^8=3D256) all were zero. This makes sense if we assume that >> > md5 returns a number which the ereg in new_id casts as a string, and >> > so ignores the leading zero. >> > >> > I've fixed zids.php3 to allow 12..16 character packed ids, and 24..32 >> > long, but this could break my tagged ids. I've also fixed >> > util.php3.new_id to only return a string of exactly 16 chars. >> > >> > > >5) In zids.php3 you wrote: >> >> > >> >> >function id_t2l(&$str) { >> >> >#TODO: Look online for quicker way to substr last 32 chars - mitra >> >> > if (ereg("(.*)([0-9a-f]{32})",$str,$parts)) >> >> > return $parts[2]; >> >> > >> >> >The quicker way is: substr($str, -32), but see 3) >> >> >> >> Ok - I'll make this 24..32, and I guess we can't use tags that end i= n >> >> a hex character [0-9a-f) >> > >> >Or you can use some delimeter (tag:unpacked_id). As I write before, we >> >never use tags so far, so the syntax is on your choice. >> >> >> require "../include/config.php3"; >> require $GLOBALS[AA_INC_PATH]."util.php3"; >> >> $i =3D 0; >> $j=3D 99999; >> print "<br>Testing start, loops=3D$j: sample=3D"; > > $foo =3D new_id(); >> print $foo; >> while ($i++ < $j) { >> $foo =3D new_id(); >> if (strlen($foo) !=3D 32) print "<br>FOO:$i:$foo:strlen=3D".strlen($foo)= ; >> if (strlen(pack_id($foo)) !=3D 16) print "<br>FOO:$i:$foo:packed >> strlen=3D".strlen(\ >> pack_id($foo)); >> } >> print "<br>Testing end sample =3D "; >> $foo =3D new_id(); >> print $foo; >> >> print "Done\n"; >> > > > >------------------------------------------------------- >This SF.NET email is sponsored by: >SourceForge Enterprise Edition + IBM + LinuxWorld http://www.vasoftware.com >_______________________________________________ >Apc-aa-coders mailing list >Apc...@li... >https://lists.sourceforge.net/lists/listinfo/apc-aa-coders -- Mitra Technology Consulting - www.mitra.biz - mi...@mi... 02-6684-8096 or 0414-648-0722 Life is a Mystery to be Lived, not a Problem to be Solved |