From d8ea359d48f9e75265411b2229b42898b5249f04 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Mon, 30 May 2022 09:36:08 +0200 Subject: [PATCH] create first counter --- Lab04/code/.gitignore | 99 ++++++++++++++++++++++++++++++++++++++ Lab04/code/part01/go.mod | 3 ++ Lab04/code/part01/main.go | 27 +++++++++++ Lab04/code/part01/makefile | 17 +++++++ 4 files changed, 146 insertions(+) create mode 100644 Lab04/code/.gitignore create mode 100644 Lab04/code/part01/go.mod create mode 100644 Lab04/code/part01/main.go create mode 100644 Lab04/code/part01/makefile diff --git a/Lab04/code/.gitignore b/Lab04/code/.gitignore new file mode 100644 index 0000000..241c324 --- /dev/null +++ b/Lab04/code/.gitignore @@ -0,0 +1,99 @@ +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### Linux template +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Windows template +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +.idea/ +part01/frequency \ No newline at end of file diff --git a/Lab04/code/part01/go.mod b/Lab04/code/part01/go.mod new file mode 100644 index 0000000..7d143a9 --- /dev/null +++ b/Lab04/code/part01/go.mod @@ -0,0 +1,3 @@ +module frequency + +go 1.18 diff --git a/Lab04/code/part01/main.go b/Lab04/code/part01/main.go new file mode 100644 index 0000000..2332f8a --- /dev/null +++ b/Lab04/code/part01/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "strings" +) + +func wordCount(str string) map[string]int { + wordList := strings.Fields(str) + counts := make(map[string]int) + for _, word := range wordList { + _, ok := counts[word] + if ok { + counts[word] += 1 + } else { + counts[word] = 1 + } + } + return counts +} + +func main() { + strLine := "Australia Canada Germany Australia Japan Canada" + for index,element := range wordCount(strLine){ + fmt.Println(index,"=>",element) + } +} \ No newline at end of file diff --git a/Lab04/code/part01/makefile b/Lab04/code/part01/makefile new file mode 100644 index 0000000..97fb1c3 --- /dev/null +++ b/Lab04/code/part01/makefile @@ -0,0 +1,17 @@ +# Go parameters +GoCMD=go +GoBUILD=$(GoCMD) build +GoCLEAN=$(GoCMD) clean +GoTEST=$(GoCMD) test +GoMOD=$(GoCMD) mod +BINARY_NAME=frequency + +# To install GoLang please follow the installation instructions on https://go.dev/ +all: build +build: + $(GoBUILD) -o $(BINARY_NAME) -v +clean: + $(GOCLEAN) + rm -f $(BINARY_NAME) +deps: + $(GoMOD) tidy \ No newline at end of file