public void SeparateChainingHashSTTest() { SeparateChainingHashST<IComparable, string> st = new SeparateChainingHashST<IComparable, string>(); string[] searchExample = new[] { "S", "E", "A", "R", "C", "H", "E", "X", "A", "M", "P", "L" }; foreach (string val in searchExample) { st.Put(val, val); } foreach (string s in searchExample) { Assert.AreEqual(st.Get(s), s); } }
static void Main(string[] args) { ST <string, string> st; st = new SequentialSearchST <string, string>(); st.Put("a", "1"); st.Put("b", "2"); int size = st.Size(); st.Delete("a"); size = st.Size(); SortedST <string, string> sortedSt; sortedSt = new BST <string, string>(); sortedSt.Put("r", "1"); sortedSt.Put("b", "2"); sortedSt.Put("h", "3"); sortedSt.Put("t", "4"); sortedSt.Delete("b"); st = new SeparateChainingHashST <string, string>(); st.Put("f", "1"); st.Put("a", "3"); st.Put("d", "4"); st.Put("h", "9"); st.Put("k", "8"); var v = st.Get("h"); st = new LinearProbingHashST <string, string>(); st.Put("f", "1"); st.Put("a", "3"); st.Put("d", "4"); st.Put("h", "9"); st.Put("u", "8"); v = st.Get("u"); Console.ReadKey(); }
public void TestSeparateChainingHashST() { SeparateChainingHashST<string, int> st = new SeparateChainingHashST<string, int>(); int amounts = 20; string[] strs = new string[amounts]; Random rand = new Random(); for (int i = 0; i < amounts; i++) { strs[i] = Convert.ToChar(rand.Next(97, 122)).ToString(); st.Put(strs[i], i); } StringBuilder sb0 = new StringBuilder(); foreach (var str in strs) sb0.Append(str + " "); Debug.WriteLine(sb0.ToString()); StringBuilder sb = new StringBuilder(); foreach (var item in st.Keys()) sb.Append(item + "-" + st.Get(item) + " "); Debug.WriteLine(sb.ToString()); Assert.AreEqual(strs.Distinct().Count(), st.Keys().Count()); }