From b74a37dd858108810ae3cf2237dee7e4611aaa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20=C3=96zelo=C4=9Flu?= Date: Mon, 28 Mar 2022 22:39:29 +0300 Subject: [PATCH] Update README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gökhan Özeloğlu --- README.md | 87 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3784ae6..d611a12 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ -# set [![Go Reference](https://pkg.go.dev/badge/github.com/gozeloglu/set.svg)](https://pkg.go.dev/github.com/gozeloglu/set) - +# set +[![Go Reference](https://pkg.go.dev/badge/github.com/gozeloglu/set.svg)](https://pkg.go.dev/github.com/gozeloglu/set) +[![Go Report Card](https://goreportcard.com/badge/github.com/gozeloglu/set)](https://goreportcard.com/report/github.com/gozeloglu/set) +[![GoCover](http://gocover.io/_badge/github.com/gozeloglu/set)](http://gocover.io/github.com/gozeloglu/set) +---- `set` is a data structure package written by **Go**. It provides some basic set functionalities of the user. It uses -`map` data structure under the hood. It does not have any dependency. +`map` data structure under the hood. + +* Written in vanilla Go with no dependency. +* Supports thread-safety. +* Two different set options. Thread-safe and Thread-unsafe. +* Supports any data type(integer, float, string, byte, and so on). ## Installation @@ -10,7 +18,7 @@ go get github.com/gozeloglu/set ``` -## Example +## Thread Unsafe Set Example ```go package main @@ -21,27 +29,63 @@ import ( ) func main() { - s := set.New(set.ThreadUnsafe) - s.Add(123) + unsafeSet := set.New(set.ThreadUnsafe) + unsafeSet.Add(123) - exist := s.Contains(123) + exist := unsafeSet.Contains(123) if !exist { fmt.Println("123 not exist") } - s.Append(1, 2, 3, 4, "abc") // Add multiple values + unsafeSet.Append(1, 2, 3, 4, "abc") // Add multiple values values := []interface{}{"github", 100, 640, 0.43, false} - s.Append(values...) // Append the array of elements + unsafeSet.Append(values...) // Append the array of elements - s.Remove(4) - size := s.Size() + unsafeSet.Remove(4) + size := unsafeSet.Size() fmt.Println(size) // Prints 5 - s.Pop() // Returns random value from the set - s.Clear() - fmt.Println(s.Size()) // Prints 0 + unsafeSet.Pop() // Returns random value from the set + unsafeSet.Clear() + fmt.Println(unsafeSet.Size()) // Prints 0 - if s.Empty() { + if unsafeSet.Empty() { + fmt.Println("set is empty") + } +} +``` + +## Thread Safe Set Example + +```go +package main + +import ( + "fmt" + "github.com/gozeloglu/set" +) + +func main() { + safeSet := set.New(set.ThreadSafe) + safeSet.Append(1, 2, 3, 4) // Add multiple values + + exist := safeSet.Contains(2) + if !exist { + fmt.Println("2 not exist") + } + + values := []interface{}{"github", 100, 640, 0.43, false} + safeSet.Append(values...) // Append the array of elements + + safeSet.Remove(4) + size := safeSet.Size() + fmt.Println(size) + + safeSet.Pop() + safeSet.Clear() + fmt.Println(safeSet.Size()) + + if safeSet.Empty() { fmt.Println("set is empty") } } @@ -72,14 +116,11 @@ func main() { You can run the tests with the following command. ```shell -go test ./... -``` - -You can check the code coverage with the following commands: - -```shell -go test -coverprofile=coverage.out -go tool cover -html=coverage.out -o coverage.html +make test # Runs all tests +make test-v # Runs all tests with -v option +make cover # Runs all tests with -cover option. Prints out coverage result +make race # Runs all tests with -race option. +make bench # Runs benchmarks ``` ## LICENSE