Add option for choosing hash algo
This commit is contained in:
parent
9d6b1385c8
commit
d80a5f5e6b
@ -8,7 +8,7 @@ public class Program {
|
|||||||
Console.WriteLine("Please specify an option.");
|
Console.WriteLine("Please specify an option.");
|
||||||
PrintAvailableOptions();
|
PrintAvailableOptions();
|
||||||
return;
|
return;
|
||||||
} else if (args.Length > 1 && args[0] != "compareDatabases") {
|
} else if (args.Length > 3) {
|
||||||
Console.WriteLine("Too many options.");
|
Console.WriteLine("Too many options.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -25,7 +25,15 @@ public class Program {
|
|||||||
Console.WriteLine("Starting the checksum process.");
|
Console.WriteLine("Starting the checksum process.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
|
|
||||||
utils.doTheThing();
|
try {
|
||||||
|
int bufferSize = int.Parse(args[2]);
|
||||||
|
utils.doTheThing(args[1], bufferSize);
|
||||||
|
}
|
||||||
|
catch (FormatException) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("Buffer was not a valid integer value. Please specify a valid integer value for the buffer size");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("Checksum process finished");
|
Console.WriteLine("Checksum process finished");
|
||||||
@ -57,7 +65,7 @@ public class Program {
|
|||||||
|
|
||||||
static void PrintAvailableOptions() {
|
static void PrintAvailableOptions() {
|
||||||
String[] options = {
|
String[] options = {
|
||||||
"checksum",
|
"checksum - MD5, Murmur and XxHash",
|
||||||
"compareDatabases",
|
"compareDatabases",
|
||||||
"compareChecksums",
|
"compareChecksums",
|
||||||
"createDB",
|
"createDB",
|
||||||
|
@ -109,12 +109,12 @@ public class ChksumUtils {
|
|||||||
return new Dictionary<string, string>(checksums);
|
return new Dictionary<string, string>(checksums);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, uint> CalculateChecksumsWithMurmur(string[] filenames) {
|
private Dictionary<string, uint> CalculateChecksumsWithMurmur(string[] filenames, int userDefinedBufferSize) {
|
||||||
ConcurrentDictionary<string, uint> checksums = new ConcurrentDictionary<string, uint>();
|
ConcurrentDictionary<string, uint> checksums = new ConcurrentDictionary<string, uint>();
|
||||||
|
|
||||||
Parallel.ForEach(filenames, (filename, state) => {
|
Parallel.ForEach(filenames, (filename, state) => {
|
||||||
using (var stream = File.OpenRead(filename)) {
|
using (var stream = File.OpenRead(filename)) {
|
||||||
var hash = CalculateMurmurHash32(stream);
|
var hash = CalculateMurmurHash32(stream, userDefinedBufferSize);
|
||||||
lock (checksums) {
|
lock (checksums) {
|
||||||
checksums.TryAdd(filename, hash);
|
checksums.TryAdd(filename, hash);
|
||||||
}
|
}
|
||||||
@ -125,8 +125,8 @@ public class ChksumUtils {
|
|||||||
return new Dictionary<string, uint>(checksums);
|
return new Dictionary<string, uint>(checksums);
|
||||||
}
|
}
|
||||||
|
|
||||||
private uint CalculateMurmurHash32(Stream stream) {
|
private uint CalculateMurmurHash32(Stream stream, int userDefinedBufferSize) {
|
||||||
const int bufferSize = 4096;
|
int bufferSize = userDefinedBufferSize;
|
||||||
const uint seed = 123456U;
|
const uint seed = 123456U;
|
||||||
|
|
||||||
var buffer = new byte[bufferSize];
|
var buffer = new byte[bufferSize];
|
||||||
@ -141,12 +141,12 @@ public class ChksumUtils {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, ulong> CalculateChecksumsWithXxHash3(string[] filenames) {
|
private Dictionary<string, ulong> CalculateChecksumsWithXxHash3(string[] filenames, int userDefinedBufferSize) {
|
||||||
ConcurrentDictionary<string, ulong> checksums = new ConcurrentDictionary<string, ulong>();
|
ConcurrentDictionary<string, ulong> checksums = new ConcurrentDictionary<string, ulong>();
|
||||||
|
|
||||||
Parallel.ForEach(filenames, (filename, state) => {
|
Parallel.ForEach(filenames, (filename, state) => {
|
||||||
using (var stream = File.OpenRead(filename)) {
|
using (var stream = File.OpenRead(filename)) {
|
||||||
var hash = CalculateXxHash3(stream);
|
var hash = CalculateXxHash3(stream, userDefinedBufferSize);
|
||||||
checksums.TryAdd(filename, hash);
|
checksums.TryAdd(filename, hash);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -154,8 +154,8 @@ public class ChksumUtils {
|
|||||||
return new Dictionary<string, ulong>(checksums);
|
return new Dictionary<string, ulong>(checksums);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ulong CalculateXxHash3(Stream stream) {
|
private ulong CalculateXxHash3(Stream stream, int userDefinedBufferSize) {
|
||||||
const int bufferSize = 4096;
|
int bufferSize = userDefinedBufferSize;
|
||||||
const ulong seed = 123456U;
|
const ulong seed = 123456U;
|
||||||
|
|
||||||
var buffer = new byte[bufferSize];
|
var buffer = new byte[bufferSize];
|
||||||
@ -190,11 +190,11 @@ public class ChksumUtils {
|
|||||||
fileHashes = fileHashesMD5.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
fileHashes = fileHashesMD5.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
||||||
break;
|
break;
|
||||||
case "Murmur":
|
case "Murmur":
|
||||||
fileHashesMurmur = CalculateChecksumsWithMurmur(indexFiles());
|
fileHashesMurmur = CalculateChecksumsWithMurmur(indexFiles(), bufferSize);
|
||||||
fileHashes = fileHashesMurmur.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
fileHashes = fileHashesMurmur.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
||||||
break;
|
break;
|
||||||
case "XxHash":
|
case "XxHash":
|
||||||
fileHashesXxHash3 = CalculateChecksumsWithXxHash3(indexFiles());
|
fileHashesXxHash3 = CalculateChecksumsWithXxHash3(indexFiles(), bufferSize);
|
||||||
fileHashes = fileHashesXxHash3.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
fileHashes = fileHashesXxHash3.ToDictionary(kv => kv.Key, kv => (object)kv.Value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user