develooper Front page | perl.perl5.porters | Postings from July 2018

regen/mph.pl reuse troubles

Thread Next
From:
bulk 88
Date:
July 4, 2018 14:45
Subject:
regen/mph.pl reuse troubles
Message ID:
BN6PR04MB096395523E62111C385BC37FDF410@BN6PR04MB0963.namprd04.prod.outlook.com
I am trying to use mph.pl for another use in Perl. mph.pl generates a 
lookup func like this.
--------------------------------------
MPH_VALt match_uniprop( const unsigned char * const key, const U16 
key_len ) {
     const unsigned char * ptr= key;
     const unsigned char * ptr_end= key + key_len;
     U32 h= MPH_SEED1;
     U32 s;
     U32 n;
     do {
         h ^= *ptr;
         h *= MPH_FNV_CONST;
     } while ( ++ptr < ptr_end );
     n= h % MPH_BUCKETS;
     s = mph_table[n].seed2;
     if (s) {
         h= (h >> MPH_RSHIFT) ^ s;
         n = h % MPH_BUCKETS;
         if (
             ( mph_table[n].pfx_len + mph_table[n].sfx_len == key_len ) &&
             ( memcmp(mph_blob + mph_table[n].pfx, key, 
mph_table[n].pfx_len) == 0 ) &&
             ( !mph_table[n].sfx_len || memcmp(mph_blob + mph_table[n].sfx,
                 key + mph_table[n].pfx_len, mph_table[n].sfx_len) == 0 )
         ) {
             return mph_table[n].value;
         }
     }
     return 0;
}
--------------------------------------
Many of my "keys" are "not found" since their "seed2" is 0, or "seed2" 
is non-0 and is a redirect to the final correct key. How is this code 
supposed to work?

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About