Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
  • Loading branch information
gozeloglu committed Mar 28, 2022
1 parent 2984793 commit b74a37d
Showing 1 changed file with 64 additions and 23 deletions.
87 changes: 64 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,7 +18,7 @@ go get github.com/gozeloglu/set
```


## Example
## Thread Unsafe Set Example

```go
package main
Expand All @@ -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")
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b74a37d

Please sign in to comment.