Skip to content

Instantly share code, notes, and snippets.

@lkrych
Created August 11, 2018 18:49
Show Gist options
  • Save lkrych/2058a73fdbaa76662e8cdccd2aee5af1 to your computer and use it in GitHub Desktop.
Save lkrych/2058a73fdbaa76662e8cdccd2aee5af1 to your computer and use it in GitHub Desktop.
Main function of frequency table construction
package main
import (
"fmt"
"io/ioutil"
"log"
"regexp"
"strings"
flags "github.com/jessevdk/go-flags"
)
var opts struct {
File string `short:"f" long:"file" description:"a file to read strings from."`
}
func main() {
//interpret the CL stdin
flags.Parse(&opts)
file, err := ioutil.ReadFile(opts.File)
checkErr(err)
//create an array of strings that is split by the newline character
splitByWord := strings.Split(string(file), " ")
table := createFreqTable(splitByWord)
fmt.Println("The frequency table is")
wordCount := 0
for _, node := range table.keys() {
wordCount++
fmt.Printf("%v -> %v \n", node.key, node.val)
}
fmt.Println("The number of unique words is", wordCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment