New hash functions according to benchmarks posted yesterday. (The IPv6
version has not been benchmarked yet due to insufficient test data.) Now ipa_hash() returns a uniformely distributed 16-bit value.
This commit is contained in:
parent
a05406e69c
commit
a6f250f5c6
2 changed files with 5 additions and 3 deletions
|
@ -61,10 +61,12 @@ typedef u32 ip_addr;
|
||||||
int ipv4_classify(u32);
|
int ipv4_classify(u32);
|
||||||
u32 ipv4_class_mask(u32);
|
u32 ipv4_class_mask(u32);
|
||||||
|
|
||||||
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
|
|
||||||
static inline unsigned ipv4_hash(u32 a)
|
static inline unsigned ipv4_hash(u32 a)
|
||||||
{
|
{
|
||||||
return a ^ (a >> 16) ^ (a >> 24);
|
/* Returns a 16-bit value */
|
||||||
|
a ^= a >> 16;
|
||||||
|
a ^= a << 10;
|
||||||
|
return a & 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -59,7 +59,7 @@ void ipv6_ntoh(ip_addr *);
|
||||||
static inline unsigned ipv6_hash(ip_addr *a)
|
static inline unsigned ipv6_hash(ip_addr *a)
|
||||||
{
|
{
|
||||||
u32 x = _I0(*a) ^ _I1(*a) ^ _I2(*a) ^ _I3(*a);
|
u32 x = _I0(*a) ^ _I1(*a) ^ _I2(*a) ^ _I3(*a);
|
||||||
return x ^ (x >> 16) ^ (x >> 8);
|
return (x ^ (x >> 16) ^ (x >> 8)) & 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue