[Mono-list] String.GetHashcode

Juan Urroa observer1 at hotmail.es
Wed Jul 15 13:56:14 EDT 2009


Hi,
I must duplicate the behavior of .net string.GetHashCode in mono I used
reflector to get this code:
public static class HashCode {
		public static unsafe int GetCode(string value) {
			fixed(char* str = ((char*)value)) {
				char* chPtr = str;
				int num = 0x15051505;
				int num2 = num;
				int* numPtr = (int*)chPtr;
				for(int i = value.Length; i > 0; i -= 4) {
					num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0];
					if(i <= 2) {
						break;
					}
					num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ numPtr[1];
					numPtr += 2;
				}
				return (num + (num2 * 0x5d588b65));
			}
		}
	}
but it doesn't compile the error is 'Cannot convert type 'string' to
'char*''

Can somebody help me with this

Thanks

-- 
View this message in context: http://www.nabble.com/String.GetHashcode-tp24502903p24502903.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list