Skip to content

Commit

Permalink
docs: Update README for add and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
1eedaegon committed Mar 29, 2024
1 parent fd9a09e commit 7ea9161
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ A go library hashset for O(1)

## Example

Initialize set and Add element

```go
import (
...
hashset "github.com/1eedaegon/go-hashset"
...
)

s := hashset.New(1, 2, "3")
s.Add("3") // Since "3" already exists in the Set, its size remains 3.
```

Remove and Distinguish between different types

```go
import (
...
hashset "github.com/1eedaegon/go-hashset"
...
)
s := hashset.New("1", "2", 3)
s.Remove("1")
s.Remove("multiple")
s.Remove("3") // The length of s is 2, because due to the difference in types.
```

## License
Expand Down
6 changes: 4 additions & 2 deletions hashset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import (
1. 추가
2. 삭제
3. 요소 확인
1. 값의 중복이 없어야한다.
2. slice가오면 set으로 변경되어야한다.
3. set을 slice로 변경할 수 있어야한다.
4. set(집합) 연산이 가능해야한다.
1. intersection
2. union
3. difference
5. 거의 모든타입 지원이 되어야한다.
6. 같은 set에 대해 동시작업이 원자성을 보장받아야한다.
*/
Expand All @@ -35,6 +33,10 @@ func TestInitializeFromArguments(t *testing.T) {

s.Add("3") // It lengths is 3, because Set already has "3"
require.NotEqual(t, 4, s.Len())

s1 := New([]int{1, 2, 3})
require.Equal(t, 1, s1.Len()) // Not comparable type, just save pointer
require.False(t, s1.Contains(2))
}

// Basic operations: 1. Add element
Expand Down

0 comments on commit 7ea9161

Please sign in to comment.