Compare commits
No commits in common. "v1.1.0-rc.1" and "v1.0.1-rc.10" have entirely different histories.
v1.1.0-rc.
...
v1.0.1-rc.
@ -5,6 +5,7 @@ when:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
test:
|
test:
|
||||||
|
group: test
|
||||||
image: golang:1.22-alpine
|
image: golang:1.22-alpine
|
||||||
commands:
|
commands:
|
||||||
- go test -v ./...
|
- go test -v ./...
|
||||||
|
17
CHANGELOG.md
17
CHANGELOG.md
@ -1,20 +1,3 @@
|
|||||||
## [1.1.0-rc.1](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.10...v1.1.0-rc.1) (2024-05-27)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* **set:** add `NewFromSlice` function ([c228caa](https://git.ext.icikowski.pl/go/sets/commit/c228caa309db0637871134fbdb386c4af55d0f14))
|
|
||||||
|
|
||||||
|
|
||||||
### Refactoring
|
|
||||||
|
|
||||||
* **comments:** beautify comments ([f8c0f0e](https://git.ext.icikowski.pl/go/sets/commit/f8c0f0eddb6ad92b146f0c87c3f087124266db56))
|
|
||||||
|
|
||||||
|
|
||||||
### Continuous Integrations
|
|
||||||
|
|
||||||
* **test:** remove `group` directive ([2f56894](https://git.ext.icikowski.pl/go/sets/commit/2f56894b6a3f85fd98fad9191c2e6a5f25dced9f))
|
|
||||||
|
|
||||||
## [1.0.1-rc.10](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.9...v1.0.1-rc.10) (2024-05-21)
|
## [1.0.1-rc.10](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.9...v1.0.1-rc.10) (2024-05-21)
|
||||||
|
|
||||||
|
|
||||||
|
10
functions.go
10
functions.go
@ -1,6 +1,6 @@
|
|||||||
package sets
|
package sets
|
||||||
|
|
||||||
// Union returns a union of the given sets (left ∪ right).
|
// Union returns a union of the given sets (left ∪ right)
|
||||||
func Union[T comparable](left, right *Set[T]) *Set[T] {
|
func Union[T comparable](left, right *Set[T]) *Set[T] {
|
||||||
left.mux.RLock()
|
left.mux.RLock()
|
||||||
right.mux.RLock()
|
right.mux.RLock()
|
||||||
@ -23,7 +23,7 @@ func Union[T comparable](left, right *Set[T]) *Set[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intersection returns an intersection of the given sets (left ∩ right).
|
// Intersection returns an intersection of the given sets (left ∩ right)
|
||||||
func Intersection[T comparable](left, right *Set[T]) *Set[T] {
|
func Intersection[T comparable](left, right *Set[T]) *Set[T] {
|
||||||
left.mux.RLock()
|
left.mux.RLock()
|
||||||
right.mux.RLock()
|
right.mux.RLock()
|
||||||
@ -43,7 +43,7 @@ func Intersection[T comparable](left, right *Set[T]) *Set[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diff returns the relative complement of sets (left ∖ right).
|
// Diff returns the relative complement of sets (left ∖ right)
|
||||||
func Diff[T comparable](left, right *Set[T]) *Set[T] {
|
func Diff[T comparable](left, right *Set[T]) *Set[T] {
|
||||||
left.mux.RLock()
|
left.mux.RLock()
|
||||||
right.mux.RLock()
|
right.mux.RLock()
|
||||||
@ -63,7 +63,7 @@ func Diff[T comparable](left, right *Set[T]) *Set[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SymmetricDiff returns the symmetric difference between sets (left ⊖ right).
|
// SymmetricDiff returns the symmetric difference between sets (left ⊖ right)
|
||||||
func SymmetricDiff[T comparable](left, right *Set[T]) *Set[T] {
|
func SymmetricDiff[T comparable](left, right *Set[T]) *Set[T] {
|
||||||
left.mux.RLock()
|
left.mux.RLock()
|
||||||
right.mux.RLock()
|
right.mux.RLock()
|
||||||
@ -88,7 +88,7 @@ func SymmetricDiff[T comparable](left, right *Set[T]) *Set[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal checks whether the sets are equal (left = right).
|
// Equal checks whether the sets are equal (left = right)
|
||||||
func Equal[T comparable](left, right *Set[T]) bool {
|
func Equal[T comparable](left, right *Set[T]) bool {
|
||||||
left.mux.RLock()
|
left.mux.RLock()
|
||||||
right.mux.RLock()
|
right.mux.RLock()
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "sets",
|
"name": "sets",
|
||||||
"version": "1.1.0-rc.1",
|
"version": "1.0.1-rc.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "sets",
|
"name": "sets",
|
||||||
"version": "1.1.0-rc.1",
|
"version": "1.0.1-rc.10",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@saithodev/semantic-release-gitea": "^2.1.0",
|
"@saithodev/semantic-release-gitea": "^2.1.0",
|
||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "sets",
|
"name": "sets",
|
||||||
"version": "1.1.0-rc.1",
|
"version": "1.0.1-rc.10",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"release": "./node_modules/.bin/semantic-release"
|
"release": "./node_modules/.bin/semantic-release"
|
||||||
},
|
},
|
||||||
|
19
set.go
19
set.go
@ -4,13 +4,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set represents a set of values.
|
// Set represents a set of values
|
||||||
type Set[T comparable] struct {
|
type Set[T comparable] struct {
|
||||||
store map[T]struct{}
|
store map[T]struct{}
|
||||||
mux sync.RWMutex
|
mux sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new set.
|
// New creates a new set
|
||||||
func New[T comparable](data ...T) *Set[T] {
|
func New[T comparable](data ...T) *Set[T] {
|
||||||
set := &Set[T]{
|
set := &Set[T]{
|
||||||
store: map[T]struct{}{},
|
store: map[T]struct{}{},
|
||||||
@ -22,12 +22,7 @@ func New[T comparable](data ...T) *Set[T] {
|
|||||||
return set
|
return set
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromSlice creates a new set from a slice.
|
// Size returns number of elements in set
|
||||||
func NewFromSlice[T comparable](data []T) *Set[T] {
|
|
||||||
return New[T](data...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size returns number of elements in set.
|
|
||||||
func (s *Set[T]) Size() int {
|
func (s *Set[T]) Size() int {
|
||||||
s.mux.RLock()
|
s.mux.RLock()
|
||||||
defer s.mux.RUnlock()
|
defer s.mux.RUnlock()
|
||||||
@ -35,7 +30,7 @@ func (s *Set[T]) Size() int {
|
|||||||
return len(s.store)
|
return len(s.store)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains checks whether the value is contained in the set.
|
// Contains checks whether the value is contained in the set
|
||||||
func (s *Set[T]) Contains(val T) bool {
|
func (s *Set[T]) Contains(val T) bool {
|
||||||
s.mux.RLock()
|
s.mux.RLock()
|
||||||
defer s.mux.RUnlock()
|
defer s.mux.RUnlock()
|
||||||
@ -44,7 +39,7 @@ func (s *Set[T]) Contains(val T) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert inserts a value into the set if the value was not already present.
|
// Insert inserts a value into the set if the value was not already present
|
||||||
func (s *Set[T]) Insert(val T) bool {
|
func (s *Set[T]) Insert(val T) bool {
|
||||||
s.mux.Lock()
|
s.mux.Lock()
|
||||||
defer s.mux.Unlock()
|
defer s.mux.Unlock()
|
||||||
@ -56,7 +51,7 @@ func (s *Set[T]) Insert(val T) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes a value from the set if the value was already present.
|
// Delete removes a value from the set if the value was already present
|
||||||
func (s *Set[T]) Delete(val T) bool {
|
func (s *Set[T]) Delete(val T) bool {
|
||||||
s.mux.Lock()
|
s.mux.Lock()
|
||||||
defer s.mux.Unlock()
|
defer s.mux.Unlock()
|
||||||
@ -68,7 +63,7 @@ func (s *Set[T]) Delete(val T) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slice returns a slice which contains the elements from the set.
|
// Slice returns a slice which contains the elements from the set
|
||||||
func (s *Set[T]) Slice() []T {
|
func (s *Set[T]) Slice() []T {
|
||||||
s.mux.RLock()
|
s.mux.RLock()
|
||||||
defer s.mux.RUnlock()
|
defer s.mux.RUnlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user