Skip to content

Commit 09e002e

Browse files
committed
docs: add Set into README
1 parent 0ff6187 commit 09e002e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,46 @@ func main() {
4242

4343
## Data Structures
4444

45+
Certainly! Below is a README for the `Set` struct, following the format you provided:
46+
47+
---
48+
49+
# Set
50+
51+
A set represents a collection of unique items.
52+
53+
## Type
54+
55+
```go
56+
type Set[T comparable]
57+
```
58+
59+
## Constructor
60+
61+
```go
62+
func New[T comparable]() *Set[T]
63+
```
64+
65+
## Methods
66+
67+
- `Add(item T)`: Adds an item to the set.
68+
- `Remove(item T)`: Removes an item from the set.
69+
- `Has(item T) bool`: Returns `true` if the set contains the specified item.
70+
- `Clear()`: Removes all items from the set.
71+
- `Len() int`: Returns the number of items in the set.
72+
- `IsEmpty() bool`: Returns `true` if the set is empty.
73+
- `Elements() []T`: Returns a slice containing all items in the set.
74+
- `AddAll(items ...T)`: Adds multiple items to the set.
75+
- `RemoveAll(items ...T)`: Removes multiple items from the set.
76+
- `Diff(other *Set[T]) *Set[T]`: Returns a new set containing items that are in the receiver set but not in the other set.
77+
- `Intersect(other *Set[T]) *Set[T]`: Returns a new set containing items that are in both the receiver set and the other set.
78+
- `Union(other *Set[T]) *Set[T]`: Returns a new set containing items that are in either the receiver set or the other set.
79+
- `IsSubset(other *Set[T]) bool`: Returns `true` if the receiver set is a subset of the other set.
80+
- `IsSuperset(other *Set[T]) bool`: Returns `true` if the receiver set is a superset of the other set.
81+
- `Equal(other *Set[T]) bool`: Returns `true` if the receiver set is equal to the other set.
82+
83+
---
84+
4585
### Deque
4686

4787
A double-ended queue (Deque) allows adding and removing elements from both the front and the back.

0 commit comments

Comments
 (0)