From 7ea9161d56e374da98b344d2ecb1d7e11b2de247 Mon Sep 17 00:00:00 2001 From: 1eedaegon Date: Sat, 30 Mar 2024 01:54:45 +0900 Subject: [PATCH] docs: Update README for add and remove --- README.md | 18 ++++++++++++++++++ hashset_test.go | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c41b847..a2e02c3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ A go library hashset for O(1) ## Example +Initialize set and Add element + ```go import ( ... @@ -15,6 +17,22 @@ import ( ... ) + 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 diff --git a/hashset_test.go b/hashset_test.go index 1511c17..7a522d9 100644 --- a/hashset_test.go +++ b/hashset_test.go @@ -14,7 +14,6 @@ import ( 1. 추가 2. 삭제 3. 요소 확인 - 1. 값의 중복이 없어야한다. 2. slice가오면 set으로 변경되어야한다. 3. set을 slice로 변경할 수 있어야한다. @@ -22,7 +21,6 @@ import ( 1. intersection 2. union 3. difference - 5. 거의 모든타입 지원이 되어야한다. 6. 같은 set에 대해 동시작업이 원자성을 보장받아야한다. */ @@ -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