Skip to content

Commit

Permalink
Added code so far
Browse files Browse the repository at this point in the history
  • Loading branch information
arookas committed Mar 14, 2016
1 parent e8fe454 commit 17c3145
Show file tree
Hide file tree
Showing 4 changed files with 701 additions and 0 deletions.
28 changes: 28 additions & 0 deletions jmpman/hash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Text;

namespace arookas {
static class hash {
public static uint calculate(string data) {
if (data == null) {
throw new ArgumentNullException("data");
}
return calculate(Encoding.ASCII.GetBytes(data));
}
public static uint calculate(byte[] data) {
if (data == null) {
throw new ArgumentNullException("data");
}
// this code is so shitty
var hash = 0u;
for (var i = 0; i < data.Length; ++i) {
hash <<= 8;
hash += data[i];
var r6 = unchecked((uint)((4993ul * hash) >> 32));
var r0 = unchecked((byte)((((hash - r6) / 2) + r6) >> 24));
hash -= r0 * 33554393u;
}
return hash;
}
}
}
Loading

0 comments on commit 17c3145

Please sign in to comment.