create first counter
This commit is contained in:
parent
2de583632e
commit
d8ea359d48
4 changed files with 146 additions and 0 deletions
99
Lab04/code/.gitignore
vendored
Normal file
99
Lab04/code/.gitignore
vendored
Normal file
|
@ -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
|
3
Lab04/code/part01/go.mod
Normal file
3
Lab04/code/part01/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module frequency
|
||||||
|
|
||||||
|
go 1.18
|
27
Lab04/code/part01/main.go
Normal file
27
Lab04/code/part01/main.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
17
Lab04/code/part01/makefile
Normal file
17
Lab04/code/part01/makefile
Normal file
|
@ -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
|
Reference in a new issue