speed up data hashcodes

This commit is contained in:
zzz
2009-08-27 03:53:41 +00:00
parent 1ecf4377c6
commit 7736545f5b
11 changed files with 72 additions and 26 deletions

View File

@ -137,10 +137,12 @@ public class Destination extends DataStructureImpl {
&& DataHelper.eq(getPublicKey(), dst.getPublicKey()); && DataHelper.eq(getPublicKey(), dst.getPublicKey());
} }
/** the public key has enough randomness in it to use it by itself for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey()) if (_publicKey == null)
+ DataHelper.hashCode(getPublicKey()); return 0;
return _publicKey.hashCode();
} }
@Override @Override

View File

@ -147,9 +147,15 @@ public class Hash extends DataStructureImpl {
return DataHelper.eq(_data, ((Hash) obj)._data); return DataHelper.eq(_data, ((Hash) obj)._data);
} }
/** a Hash is a hash, so just use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -345,12 +345,12 @@ public class LeaseSet extends DataStructureImpl {
} }
/** the destination has enough randomness in it to use it by itself for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(getEncryptionKey()) + if (_destination == null)
//(int)_version + return 0;
DataHelper.hashCode(_leases) + DataHelper.hashCode(getSignature()) return _destination.hashCode();
+ DataHelper.hashCode(getSigningKey()) + DataHelper.hashCode(getDestination());
} }
@Override @Override

View File

@ -70,9 +70,15 @@ public class PrivateKey extends DataStructureImpl {
return DataHelper.eq(_data, ((PrivateKey) obj)._data); return DataHelper.eq(_data, ((PrivateKey) obj)._data);
} }
/** the key has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -72,9 +72,15 @@ public class PublicKey extends DataStructureImpl {
return DataHelper.eq(_data, ((PublicKey) obj)._data); return DataHelper.eq(_data, ((PublicKey) obj)._data);
} }
/** the key has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -130,10 +130,10 @@ public class RouterAddress extends DataStructureImpl {
&& DataHelper.eq(getTransportStyle(), addr.getTransportStyle()); && DataHelper.eq(getTransportStyle(), addr.getTransportStyle());
} }
/** the style should be sufficient, for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return getCost() + DataHelper.hashCode(getTransportStyle()) + DataHelper.hashCode(getExpiration()) return DataHelper.hashCode(getTransportStyle());
+ DataHelper.hashCode(getOptions());
} }
@Override @Override

View File

@ -101,10 +101,12 @@ public class RouterIdentity extends DataStructureImpl {
&& DataHelper.eq(getPublicKey(), ident.getPublicKey()); && DataHelper.eq(getPublicKey(), ident.getPublicKey());
} }
/** the public key has enough randomness in it to use it by itself for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(getCertificate()) + DataHelper.hashCode(getSigningPublicKey()) if (_publicKey == null)
+ DataHelper.hashCode(getPublicKey()); return 0;
return _publicKey.hashCode();
} }
@Override @Override

View File

@ -76,9 +76,15 @@ public class SessionKey extends DataStructureImpl {
return DataHelper.eq(_data, ((SessionKey) obj)._data); return DataHelper.eq(_data, ((SessionKey) obj)._data);
} }
/** the key has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -62,9 +62,15 @@ public class Signature extends DataStructureImpl {
return DataHelper.eq(_data, ((Signature) obj)._data); return DataHelper.eq(_data, ((Signature) obj)._data);
} }
/** the sig has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -68,9 +68,15 @@ public class SigningPrivateKey extends DataStructureImpl {
return DataHelper.eq(_data, ((SigningPrivateKey) obj)._data); return DataHelper.eq(_data, ((SigningPrivateKey) obj)._data);
} }
/** the key has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override

View File

@ -67,9 +67,15 @@ public class SigningPublicKey extends DataStructureImpl {
return DataHelper.eq(_data, ((SigningPublicKey) obj)._data); return DataHelper.eq(_data, ((SigningPublicKey) obj)._data);
} }
/** the key has enough randomness in it, use the first 4 bytes for speed */
@Override @Override
public int hashCode() { public int hashCode() {
return DataHelper.hashCode(_data); int rv = 0;
if (_data != null) {
for (int i = 0; i < 4; i++)
rv ^= (_data[i] << (i*8));
}
return rv;
} }
@Override @Override