Compare commits
26 Commits
v1.0.1-rc.
...
devel
Author | SHA1 | Date | |
---|---|---|---|
|
93cc6d9fe2 | ||
6aeec235db | |||
|
2f54bb4656 | ||
c403a9d359 | |||
|
86c8940f45 | ||
f4cb82a73c | |||
|
c2fac0950e | ||
c9c1262313 | |||
|
b1a9c1287c | ||
c228caa309 | |||
f8c0f0eddb | |||
2f56894b6a | |||
|
0785baf4b7 | ||
64f99544f5 | |||
c375f893e3 | |||
7c2bc0f623 | |||
|
10a4c8ea36 | ||
28c7b9114b | |||
|
8460428ac4 | ||
38cf6dbfc2 | |||
|
88b140c072 | ||
ff8d5cd4b3 | |||
|
b59f819aa0 | ||
6148fb1dcc | |||
|
67ad1cb0bc | ||
1c49da97cc |
@ -5,7 +5,6 @@ when:
|
||||
|
||||
steps:
|
||||
test:
|
||||
group: test
|
||||
image: golang:1.22-alpine
|
||||
image: golang:1.23-alpine
|
||||
commands:
|
||||
- go test -v ./...
|
||||
|
119
CHANGELOG.md
119
CHANGELOG.md
@ -1,3 +1,122 @@
|
||||
## [1.1.1-rc.3](https://git.ext.icikowski.pl/go/sets/compare/v1.1.1-rc.2...v1.1.1-rc.3) (2024-08-20)
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update all non-major dependencies ([6aeec23](https://git.ext.icikowski.pl/go/sets/commit/6aeec235db139a31b28a93aed4bb842153fac584))
|
||||
|
||||
## [1.1.1-rc.2](https://git.ext.icikowski.pl/go/sets/compare/v1.1.1-rc.1...v1.1.1-rc.2) (2024-08-20)
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update golang docker tag to v1.23 ([c403a9d](https://git.ext.icikowski.pl/go/sets/commit/c403a9d359f993b1e1950d780328ae8b6ec34506))
|
||||
|
||||
## [1.1.1-rc.1](https://git.ext.icikowski.pl/go/sets/compare/v1.1.0...v1.1.1-rc.1) (2024-08-20)
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update all major dependencies ([f4cb82a](https://git.ext.icikowski.pl/go/sets/commit/f4cb82a73cd46315dd5a2b8287eda14b3a4d87d1))
|
||||
|
||||
## [1.1.0](https://git.ext.icikowski.pl/go/sets/compare/v1.0.0...v1.1.0) (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
|
||||
|
||||
* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([64f9954](https://git.ext.icikowski.pl/go/sets/commit/64f99544f52241ec9a2f9af1f30ba96aa8399af9))
|
||||
* **init:** add initial CI configuration ([0ac2547](https://git.ext.icikowski.pl/go/sets/commit/0ac25476ab2bee29255cf3ee5172a0848a67ebdf))
|
||||
* **renovate:** add Renovate bot configuration ([cf9d970](https://git.ext.icikowski.pl/go/sets/commit/cf9d97099df59f7906610100963320613091449b))
|
||||
* **test:** remove `group` directive ([2f56894](https://git.ext.icikowski.pl/go/sets/commit/2f56894b6a3f85fd98fad9191c2e6a5f25dced9f))
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update all non-major dependencies ([c375f89](https://git.ext.icikowski.pl/go/sets/commit/c375f893e3c2492b6a4763c4685b5afd841e6f5c))
|
||||
* **deps:** update all non-major dependencies ([efd1b2b](https://git.ext.icikowski.pl/go/sets/commit/efd1b2b347dbaf5f7cf6ed18a4112a30e32359a8))
|
||||
* **deps:** update all non-major dependencies ([b8a9834](https://git.ext.icikowski.pl/go/sets/commit/b8a9834910afd46073123648ea8afaa5749d8921))
|
||||
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([6148fb1](https://git.ext.icikowski.pl/go/sets/commit/6148fb1dccc52ce9b252baa2e1f2ad9362bc103b))
|
||||
* **deps:** update dependency @semantic-release/npm to v12 ([1c49da9](https://git.ext.icikowski.pl/go/sets/commit/1c49da97ccb172a825f5bc4cae602dcc4e235fb4))
|
||||
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([38cf6db](https://git.ext.icikowski.pl/go/sets/commit/38cf6dbfc20ef0ff18de9aedad84f31832721404))
|
||||
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([7c2bc0f](https://git.ext.icikowski.pl/go/sets/commit/7c2bc0f623ff5a82b81e9784a92b9845738c62f0))
|
||||
* **deps:** update dependency semantic-release to v23 ([1223d34](https://git.ext.icikowski.pl/go/sets/commit/1223d341e284b641fc35e6d247616dcaaf760a90))
|
||||
* **deps:** update dependency semantic-release to v23.0.3 ([6cc61a8](https://git.ext.icikowski.pl/go/sets/commit/6cc61a86efc2a46f6c0d98517916011cfcdac444))
|
||||
* **deps:** update dependency semantic-release to v23.0.4 ([f45e6e5](https://git.ext.icikowski.pl/go/sets/commit/f45e6e52ede310174421a6fe7f21f126aaaa24a4))
|
||||
* **deps:** update dependency semantic-release to v23.0.5 ([ff8d5cd](https://git.ext.icikowski.pl/go/sets/commit/ff8d5cd4b30c895b2e58e8647648694731465981))
|
||||
* **deps:** update dependency semantic-release to v23.0.8 ([28c7b91](https://git.ext.icikowski.pl/go/sets/commit/28c7b9114b2b63b55e5605e9a183bf84ea7500b0))
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
### Continuous Integrations
|
||||
|
||||
* **deps:** pin `conventional-changelog-conventionalcommits` to version 7.x ([64f9954](https://git.ext.icikowski.pl/go/sets/commit/64f99544f52241ec9a2f9af1f30ba96aa8399af9))
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update all non-major dependencies ([c375f89](https://git.ext.icikowski.pl/go/sets/commit/c375f893e3c2492b6a4763c4685b5afd841e6f5c))
|
||||
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([7c2bc0f](https://git.ext.icikowski.pl/go/sets/commit/7c2bc0f623ff5a82b81e9784a92b9845738c62f0))
|
||||
|
||||
## [1.0.1-rc.9](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.8...v1.0.1-rc.9) (2024-04-12)
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update dependency semantic-release to v23.0.8 ([28c7b91](https://git.ext.icikowski.pl/go/sets/commit/28c7b9114b2b63b55e5605e9a183bf84ea7500b0))
|
||||
|
||||
## [1.0.1-rc.8](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.7...v1.0.1-rc.8) (2024-04-12)
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update dependency @semantic-release/release-notes-generator to v13 ([38cf6db](https://git.ext.icikowski.pl/go/sets/commit/38cf6dbfc20ef0ff18de9aedad84f31832721404))
|
||||
|
||||
## [1.0.1-rc.7](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.6...v1.0.1-rc.7) (2024-03-23)
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update dependency semantic-release to v23.0.5 ([ff8d5cd](https://git.ext.icikowski.pl/go/sets/commit/ff8d5cd4b30c895b2e58e8647648694731465981))
|
||||
|
||||
## [1.0.1-rc.6](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.5...v1.0.1-rc.6) (2024-03-23)
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update dependency @semantic-release/commit-analyzer to v12 ([6148fb1](https://git.ext.icikowski.pl/go/sets/commit/6148fb1dccc52ce9b252baa2e1f2ad9362bc103b))
|
||||
|
||||
## [1.0.1-rc.5](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.4...v1.0.1-rc.5) (2024-03-17)
|
||||
|
||||
|
||||
### Build system and dependencies
|
||||
|
||||
* **deps:** update dependency @semantic-release/npm to v12 ([1c49da9](https://git.ext.icikowski.pl/go/sets/commit/1c49da97ccb172a825f5bc4cae602dcc4e235fb4))
|
||||
|
||||
## [1.0.1-rc.4](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.3...v1.0.1-rc.4) (2024-03-17)
|
||||
|
||||
|
||||
|
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# `sets`
|
||||
|
||||
[![Go Report Card](https://goreportcard.com/badge/pkg.icikowski.pl/sets)](https://goreportcard.com/report/pkg.icikowski.pl/sets)
|
||||
|
||||
Sets and useful functions for working with them.
|
10
functions.go
10
functions.go
@ -1,6 +1,6 @@
|
||||
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] {
|
||||
left.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] {
|
||||
left.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] {
|
||||
left.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] {
|
||||
left.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 {
|
||||
left.mux.RLock()
|
||||
right.mux.RLock()
|
||||
|
2800
package-lock.json
generated
2800
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
/*
|
||||
Sets-related types & functions
|
||||
Sets and useful functions for working with them.
|
||||
*/
|
||||
package sets
|
||||
|
12
package.json
12
package.json
@ -1,18 +1,18 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "sets",
|
||||
"version": "1.0.1-rc.4",
|
||||
"version": "1.1.1-rc.3",
|
||||
"scripts": {
|
||||
"release": "./node_modules/.bin/semantic-release"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@saithodev/semantic-release-gitea": "^2.1.0",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^11.0.0",
|
||||
"@semantic-release/commit-analyzer": "^13.0.0",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/npm": "^11.0.1",
|
||||
"@semantic-release/release-notes-generator": "^12.0.1",
|
||||
"conventional-changelog-conventionalcommits": "^7.0.2",
|
||||
"semantic-release": "^23.0.0"
|
||||
"@semantic-release/npm": "^12.0.0",
|
||||
"@semantic-release/release-notes-generator": "^14.0.0",
|
||||
"conventional-changelog-conventionalcommits": "^8.0.0",
|
||||
"semantic-release": "^24.0.0"
|
||||
}
|
||||
}
|
||||
|
19
set.go
19
set.go
@ -4,13 +4,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Set represents a set of values
|
||||
// Set represents a set of values.
|
||||
type Set[T comparable] struct {
|
||||
store map[T]struct{}
|
||||
mux sync.RWMutex
|
||||
}
|
||||
|
||||
// New creates a new set
|
||||
// New creates a new set.
|
||||
func New[T comparable](data ...T) *Set[T] {
|
||||
set := &Set[T]{
|
||||
store: map[T]struct{}{},
|
||||
@ -22,7 +22,12 @@ func New[T comparable](data ...T) *Set[T] {
|
||||
return set
|
||||
}
|
||||
|
||||
// Size returns number of elements in set
|
||||
// NewFromSlice creates a new set from a slice.
|
||||
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 {
|
||||
s.mux.RLock()
|
||||
defer s.mux.RUnlock()
|
||||
@ -30,7 +35,7 @@ func (s *Set[T]) Size() int {
|
||||
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 {
|
||||
s.mux.RLock()
|
||||
defer s.mux.RUnlock()
|
||||
@ -39,7 +44,7 @@ func (s *Set[T]) Contains(val T) bool {
|
||||
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 {
|
||||
s.mux.Lock()
|
||||
defer s.mux.Unlock()
|
||||
@ -51,7 +56,7 @@ func (s *Set[T]) Insert(val T) bool {
|
||||
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 {
|
||||
s.mux.Lock()
|
||||
defer s.mux.Unlock()
|
||||
@ -63,7 +68,7 @@ func (s *Set[T]) Delete(val T) bool {
|
||||
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 {
|
||||
s.mux.RLock()
|
||||
defer s.mux.RUnlock()
|
||||
|
Loading…
Reference in New Issue
Block a user