i need reverse engineer code c# , critical ouput absolutely same. suggestions on ord function , "strhash % (1<<64)" part?
def easyhash(s): """ mdsd used following hash algorithm cal first part of partition key """ strhash = 0 multiplier = 37 c in s: strhash = strhash * multiplier + ord(c) #only keep last 64bit, since mod base 100 strhash = strhash % (1<<64) return strhash % 100 #assume eventvolume large
probably this:
note i'm using ulong instead of long, because don't want after overflow there negative numbers (they mess calculation). don't need strhash = strhash % (1<<64) because ulong implicit.
public static int easyhash(string s) { ulong strhash = 0; const int multiplier = 37; (int = 0; < s.length; i++) { unchecked { strhash = (strhash * multiplier) + s[i]; } } return (int)(strhash % 100); } the unchecked keyword not necessary, because "normally" c# compiled in unchecked mode (so without checks overflows), code can compiled in checked mode (there option that). code, written, needs unchecked mode (because can have overflows), force unchecked keyword.
python: https://ideone.com/rtnsh7
Comments
Post a Comment