Naanou.Common
Class Hash

Represents hashed data, such as a node id, file, IP address etc.

Field Summary
java.math.BigInteger bigInteger
         BigInteger version of hash
int BIT_LENGTH
         Bit length of hash
int COMPARE_EQUAL
         Compare is equal
int COMPARE_GREATER
         Compare is greater
int COMPARE_LESS
         Compare is less
byte[] hash
         Hashed bytes
string keySerial
         Serialised version of key
java.math.BigDecimal MappingRatio
         Ratio of largest hash to degrees
System.Security.Cryptography.SHA1 sha_
         SHA provider
Naanou.Common.Hash ZeroHash
         Small hash

Constructor Summary
Hash()
        Initializes a new instance of the Hash class.
Hash(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
         Deserialiser
Hash(byte[] hashedBytes)
         Do not use!

Method Summary
Naanou.Common.Hash Clone()
         Clones the hash
int CompareTo(object o)
         Compares this hash and another hash. Less than zero, and this instance is less than param, zero and instance is equal and greater than zero and instance is greater than param
bool Equals(object o)
Naanou.Common.Hash FromBI(java.math.BigInteger bi)
         Creates a hash from a BigInteger instance
Naanou.Common.Hash FromSerial(string serial)
         Constructs a Hash from a serial previouslly created via Naanou.Common.Hash.GetSerial
double GetDegrees()
         Gets the value of this hash mapped to a circle (0-360 degrees) - visualisation helper
int GetHashCode()
         Gets the hash code for this hash
Naanou.Common.Hash GetHigherFinger(double fingerPowers, int power)
         Gets the higher finger of this hash
Naanou.Common.Hash GetLowerFinger(double fingerPowers, int power)
         Gets a lower finger of this hash
void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
         Serialization code
string GetSerial()
         Returns a string representation of the hash suitable for serialisation
Naanou.Common.Hash Lower(long amount)
         Gets the lower hash of this
Naanou.Common.Hash Raise(long amount)
         Gets the higher hash of this
java.math.BigInteger ToBigInteger()
         Gets a BigInteger form of the Hash
double ToDouble()
         Gets the hash as a double (warning: precision loss)
string ToNumberString()
         Gets the hash as a giant number string
string ToString()
         Gets a human-readable string representation

Methods inherited from class System.Object
Finalize, GetType, MemberwiseClone

Operator Summary
bool operator ==(Naanou.Common.Hash x, Naanou.Common.Hash y)
bool operator >(Naanou.Common.Hash x, Naanou.Common.Hash y)
bool operator >=(Naanou.Common.Hash x, Naanou.Common.Hash y)
bool operator !=(Naanou.Common.Hash x, Naanou.Common.Hash y)
bool operator <(Naanou.Common.Hash x, Naanou.Common.Hash y)
bool operator <=(Naanou.Common.Hash x, Naanou.Common.Hash y)


Field Detail

bigInteger

protected java.math.BigInteger bigInteger

BigInteger version of hash


BIT_LENGTH

public int BIT_LENGTH

Bit length of hash


COMPARE_EQUAL

public int COMPARE_EQUAL

Compare is equal


COMPARE_GREATER

public int COMPARE_GREATER

Compare is greater


COMPARE_LESS

public int COMPARE_LESS

Compare is less


hash

protected byte[] hash

Hashed bytes


keySerial

protected string keySerial

Serialised version of key


MappingRatio

public java.math.BigDecimal MappingRatio

Ratio of largest hash to degrees


sha_

public System.Security.Cryptography.SHA1 sha_

SHA provider


ZeroHash

public Naanou.Common.Hash ZeroHash

Small hash

Constructor Detail

Hash

private Hash()

Initializes a new instance of the Hash class.


Hash

public Hash(System.Runtime.Serialization.SerializationInfo info,
            System.Runtime.Serialization.StreamingContext context)

Deserialiser

Parameters:
info -
context -

Hash

public Hash(byte[] hashedBytes)

Do not use!

Parameters:
hashedBytes - Hashed bytes
Method Detail

Clone

public Naanou.Common.Hash Clone()

Clones the hash

Returns:
Clone of hash

CompareTo

public int CompareTo(object o)

Compares this hash and another hash. Less than zero, and this instance is less than param, zero and instance is equal and greater than zero and instance is greater than param

Parameters:
o - Object to compare with
Returns:
Less than zero, and this instance is less than param, zero and instance is equal and greater than zero and instance is greater than param

Equals

public bool Equals(object o)


FromBI

public Naanou.Common.Hash FromBI(java.math.BigInteger bi)

Creates a hash from a BigInteger instance

Parameters:
bi - BigInteger
Returns:
Hash

FromSerial

public Naanou.Common.Hash FromSerial(string serial)

Constructs a Hash from a serial previouslly created via Naanou.Common.Hash.GetSerial

Parameters:
serial - Serial
Returns:
Hash

GetDegrees

public double GetDegrees()

Gets the value of this hash mapped to a circle (0-360 degrees) - visualisation helper

Returns:
Degrees

GetHashCode

public int GetHashCode()

Gets the hash code for this hash

Returns:

GetHigherFinger

public Naanou.Common.Hash GetHigherFinger(double fingerPowers,
                                          int power)

Gets the higher finger of this hash

Parameters:
fingerPowers - Powers
power - Power
Returns:
Higher finger

GetLowerFinger

public Naanou.Common.Hash GetLowerFinger(double fingerPowers,
                                         int power)

Gets a lower finger of this hash

Parameters:
fingerPowers - Powers
power - Power
Returns:
Lower finger

GetObjectData

public void GetObjectData(System.Runtime.Serialization.SerializationInfo info,
                          System.Runtime.Serialization.StreamingContext context)

Serialization code

Parameters:
info -
context -

GetSerial

public string GetSerial()

Returns a string representation of the hash suitable for serialisation

Returns:
Representation of the hash suitable for serialisation

Lower

public Naanou.Common.Hash Lower(long amount)

Gets the lower hash of this

Parameters:
amount - Amount
Returns:
Lower hash

Raise

public Naanou.Common.Hash Raise(long amount)

Gets the higher hash of this

Parameters:
amount - Amount
Returns:
Higher hash

ToBigInteger

public java.math.BigInteger ToBigInteger()

Gets a BigInteger form of the Hash

Returns:

ToDouble

public double ToDouble()

Gets the hash as a double (warning: precision loss)

Returns:

ToNumberString

public string ToNumberString()

Gets the hash as a giant number string

Returns:

ToString

public string ToString()

Gets a human-readable string representation

Returns:
Human-readable string representation
Operator Detail

Equality Operator

public bool operator ==(Naanou.Common.Hash x,
                        Naanou.Common.Hash y)


Greater Than Operator

public bool operator >(Naanou.Common.Hash x,
                       Naanou.Common.Hash y)


Greater Than Or Equal Operator

public bool operator >=(Naanou.Common.Hash x,
                        Naanou.Common.Hash y)


Inequality Operator

public bool operator !=(Naanou.Common.Hash x,
                        Naanou.Common.Hash y)


Less Than Operator

public bool operator <(Naanou.Common.Hash x,
                       Naanou.Common.Hash y)


Less Than Or Equal Operator

public bool operator <=(Naanou.Common.Hash x,
                        Naanou.Common.Hash y)