What will be the best idea in the context of C#,
In C# i am using a dictionary. I want it to use less memory space. what will be better?
A dictionary where the key type is
Uint64
or where the key type is astring
? in both cases the value is a custom class which is same for each dictionary.I have declared the dictionary as following,
private static readonly Dictionary<string, List<Node>> HashTable = new Dictionary<string, List<Node>>();
class node is defined as below,
public class Node { public UInt64 CurrentIndex { get; set; } public string NextHashedString { get; set; } public int NextHashPos { get; set; } }
The key of the string is actually is a hashvalue from a string computed as follows, The length of string may be 1 to 20 characters.
static UInt64 CalculateHash(string read, bool lowTolerance) { UInt64 hashedValue = 0; int i = 0; while (i < read.Length) { hashedValue += read.ElementAt(i) * (UInt64)Math.Pow(31, i); if (lowTolerance) i += 2; else i++; } return hashedValue; }
Now, I want to store this hash value as a key to the dictionary. What will be the best idea. I use as Uint64 or I convert it to string and use string as a dictionary key. My primary goal is the dictionary uses minimum space and search time for a key is faster.
I have a file with 3571079 characters. Can I read the whole file into a string or I need advanced data structures?