Created
August 11, 2018 18:51
-
-
Save lkrych/b862b326575a06b34bc50e528d56377d to your computer and use it in GitHub Desktop.
How to build a frequency table with a Symbol Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createFreqTable(arr []string) SymbolTable { | |
st := &SymbolTable{ | |
data: &BSTree{}, | |
} | |
r := regexp.MustCompile("[ .,123456789]") | |
//iterate through words | |
for _, word := range arr { | |
if r.Match([]byte(word)) { | |
//skip punctuation, spaces or numbers | |
continue | |
} | |
//see if word can be found | |
found := st.get(word) | |
if found != nil { | |
//if so, increment the count | |
st.put(word, found.val+1) | |
} else { | |
//if not, add it to the symbol table | |
st.put(word, 1) | |
} | |
} | |
return *st | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment