algorithm - efficient string hash strategy for network json ID -


currently json key string have average length of 9 bytes, if can use avaliable algorithm make unsigned long(32 bit, 4 bytes) new id, can save lots of bandwidth between client , server. is:

before: {"player_vip_type": 'xxxx', 'player_gold_coin_count':500, 'some_other_stuff':500}

after: {0xafde0901:'xxxx', 0xaeeded02:500, 0x0030fad3:500}

i have study , test of string hash strategy mentioned in which hashing algorithm best uniqueness , speed?. if string set big enough , can't prevent key conflict. know strategy repair key conflict, won't work json id both in client , server.

so there method server-client hash json key id?

as first thought, there algorithm this:

1) if 1 string hash result does't exist, make uint_32 id , using effective uint_32 hash algorithm(the reuslt id should > oxffff), called bigger id

2) if 1 string hash result exist, make exsit , new 1 uint_16 id, using different effective uint_16 algorithm(the result id should <= 0xffff) ,this called smaller id

3) when getting string id, first use getbiggerid (id > oxffff), if not exist use getsmallerid(id <= oxffff)

does algorithm feasible , how realize ?

don't. under hood, compression involved while transferring data server client, , try interferes it.

here's idea saves memory: instead of array hundred dictionaries, each keys player_vip_type, player_gold_coin_count , some_other_stuff, send 1 dictionary these 3 keys, , each having array hundred strings or numbers value.


Comments