JOY OF HASHTABLE

dzhigner

Moderator
I've been having insomnia again! I might well learn something new, so as not to worry all night about sleep. I tried some hashtable thing. A HashTable is a storage array of items, each representing a key/value pair, just like a dictionary.

I stuffed a lemma list in a compiled resource file (I don't think this is an expert solution, but rather a beginner's hack), which I hoped could be loaded at some speed, and this method turned out just fine. Then I loaded everything in a hashtable. Bingo! Finally this programming layman saw the effect he had hoped to see for hell knows how long.

Below is the code I figured out, but I don't feel sure it's not buggy. Just a snippet to post here.

----------------------------------------------------------------------------------------------------
Public Class HashDemo

Private ResReader As New Resources.ResourceReader("lemmalist.resources")

'Know-how about compiling resource file is available at
'http://msdn.microsoft.com/library/en-us/cptools/html/cpgrfResourceFileGeneratorUtilityResgenexe.asp


Private hash As New Hashtable

' Don't have to import anything

Private Sub BtnDemo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Information about hashtable is provided at
'http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemCollectionsHashtableClassTopic.asp


Dim en As IDictionaryEnumerator = reader.GetEnumerator()
While en.MoveNext()
hash.Add(en.Key, en.Value)
End While
Console.WriteLine(hash.Count)
reader.Close()
TextBox1.AppendText(lemmatize("corpora"))
hash = nothing
End Sub


Private Function lemmatize(ByVal word As String) As String
Dim lemma As String = ""
Try
If k.ContainsKey(word) Then
lemma = CType(k.Item(word), String)
End If
Catch ex As InvalidOperationException
lemma = word
End Try
Return lemma
End Function
End Class
 

xiaoz

永远的超级管理员
Staff member
Hash, also called "associative array", is very useful in programming.
 
顶部