Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.programming,comp.unix.programmer Subject: Re: hash function over IP address Date: Mon, 09 Apr 2012 15:54:28 +0100 Lines: 39 Message-ID: <87obr1gdln.fsf@sapphire.mobileactivedefense.com> References: <87bon65l7n.fsf@sapphire.mobileactivedefense.com> <87ehs0g7nn.fsf@sapphire.mobileactivedefense.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net 35CQiGDkf1PaE0QM23dCjgsCkGz+FbcWnFkGeITXWFn3GjCE4= Cancel-Lock: sha1:AL3GNB3MMov3KyDh4/xelyQfFCw= sha1:Zf3wfQhDPeoWZPDu7Xaj1S0Vr1g= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Xref: csiph.com comp.programming:1451 comp.unix.programmer:2393 "Mark" writes: > "Rainer Weikusat" wrote in message > news:87ehs0g7nn.fsf@sapphire.mobileactivedefense.com... >>> Number of next hops is variable, thus anyway it would require to delete >>> the >>> node and re-insert it back with a new key generated, right? (that's not >>> an >>> issue though). How would you suggest to concatenate 32-bit long unsigned >>> integers, in what form -- convert to strings, concatenate and use such >>> string as a key? >> >> I would consolidate each pair into a 64-bit integer, using 0 in place >> of a possibly-missing 'second 32-bit number' and then do 'string >> comparions' on 64-bit integer strings of some length. Whether I would >> rather store an explicit length together with such a string or use a >> (64-bit) null terminator would depend on the actual circumstances. > > Thanks, this looks reasonable, however I don't understand what do you mean > by "each pair"? For instance, given three next hops: > > 10.10.10.1 > 20.20.20.1 > 30.30.30.1 > > this would yield in two 64-bit values: > > 10.10.10.1_20.20.20.1 > 30.30.30.1_0.0.0.0 Using another notataion: The three IPv4 addresses 0x0a0a0a01 0x14141401 0x1e1e1e01 would yield the two 64-bit values 0x0a0a0a0114141401 0x1e1e1e0100000000