To implement the Code keyword-based function, you need to identify each word. You need a keyword list and perform a large number of table searches. Therefore, the support for hash is essential. I will not talk much about the principles of the hash algorithm. Let's look at the code.
'================================================ ===============================< Br/> 'hash <br/> '================================================ =================================< br/> Function CreateHash () <br/> Dim hash (65535) <br/> For I = 0 To UBound (hash) <br/> hash (I) = Null <br/> Next <br/> CreateHash = hash <br/> End Function <br/> Function TransValToInt (val) <br/> Select Case VarType (val) <br/> Case vbByte, vbInteger, vbLong, vbBoolean <br/> 'int <br/> TransValToInt = val <br/> Case vbSingle, vbDouble, vbCurrency <br/> 'float <br/> TransValToInt = Int (val) <br/> Case vbDate <br/> TransValToInt = DatePart ("yyyy", val) * 31536000 + _ <br/> DatePart ("m", val) * + 2592000 + _ <br/> DatePart ("d", val) * + 86400 + _ <br/> DatePart ("h", val) * 3600 + _ <br/> DatePart ("n", val) * 60 + _ <br/> DatePart ("s", val) <br/> Case vbString <br/> Dim slen, size, res, offset </p> <p> slen = Len (val) <br/> res = slen <br/> offset = 128 <br/> If slen> 6 Then <br/> size = 6 <br/> Else <br/> size = slen <br/> End If <br/> For I = 0 To size-1 <br/> res = Asc (Mid (val, slen-I, 1 )) * offset + res <br/> offset = offset * 128 <br/> Next <br/> TransValToInt = res <br/> Case Else <br/> Log ("Unsupported type ") <br/> End Select <br/> End Function <br/> Function HashCalcKey (val) <br/> Dim key: key = TransValToInt (val) * 40503 </p> <p> If key> = 4294967295 Then <br/> key = key-Fix (key/4294967295) * 4294967295 <br/> End If <br/> key = Int (key/65535) mod 65535 <br/> HashCalcKey = key <br/> End Function <br/> Function HashExists (hash, val) <br/> Dim key: key = HashCalcKey (val) <br/> HashExists = False <br/> If key <= UBound (hash) And Not IsNull (hash (key )) then <br/> For Each item In hash (key) <br/> If item = val Then <br/> HashExists = True <br/> Exit For <br/> End If <br/> Next <br/> End If <br/> End Function <br/> Function HashAdd (hash, caseSensitive, val) <br/> If Not caseSensitive Then <br/> val = LCase (val) <br/> End If <br/> If Not HashExists (hash, val) then <br/> Dim key: key = HashCalcKey (val) <br/> If key <= UBound (hash) Then <br/> If Not IsNull (hash (key )) then <br/> Dim ary: ary = hash (key) <br/> Redim Preserve ary (UBound (ary) + 1) </p> <p> ary (UBound (ary) = val <br/> hash (key) = ary <br/> Else <br/> Dim newary () <br/> Redim newary (1) <br/> newary (0) = val <br/> hash (key) = newary <br/> End If <br/> End Function <br/> Function HashDel (hash, caseSensitive, val) <br/> If Not caseSensitive Then <br/> val = LCase (val) <br/> End If <br/> If Not HashExits (hash, val) then <br/> Dim key: key = HashCalcKey (val) <br/> If key <= UBound (hash) Then <br/> If Not IsNull (hash (key )) then <br/> Dim ary () <br/> Dim count <br/> Redim ary (UBound (hash (key ))) <br/> count = 0 <br/> For Each item In hash (key) <br/> If item <> val Then <br/> ary (count) = item <br/> count = count + 1 <br/> End If <br/> Next <br/> If count = 0 Then <br/> hash (key) = Null <br/> Else <br/> Redim Preserve ary (count-1) <br/> hash (key) = ary <br/> End If <br/> End Function <br/> Function HashClear (hash) <br/> For I = 0 To UBound (hash) <br/> hash (I) = Null <br/> Next <br/> End Function