Compare commits

...

34 Commits

Author SHA1 Message Date
c9c1262313
docs(package): add simple README.md and package description
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-05-28 01:04:58 +02:00
semantic-release-bot
b1a9c1287c release(rc): v1.1.0-rc.1
## [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](c228caa309))

### Refactoring

* **comments:** beautify comments ([f8c0f0e](f8c0f0eddb))

### Continuous Integrations

* **test:** remove `group` directive ([2f56894](2f56894b6a))
2024-05-27 23:01:22 +00:00
c228caa309
feat(set): add NewFromSlice function
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-28 00:50:19 +02:00
f8c0f0eddb
refactor(comments): beautify comments 2024-05-28 00:44:13 +02:00
2f56894b6a
ci(test): remove group directive 2024-05-28 00:38:28 +02:00
semantic-release-bot
0785baf4b7 release(rc): v1.0.1-rc.10
## [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](64f99544f5))

### Build system and dependencies

* **deps:** update all non-major dependencies ([c375f89](c375f893e3))
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([7c2bc0f](7c2bc0f623))
2024-05-21 21:04:00 +00:00
64f99544f5
ci(deps): pin conventional-changelog-conventionalcommits to version 7.x
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-05-21 23:03:28 +02:00
c375f893e3 build(deps): update all non-major dependencies
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
ci/woodpecker/push/test Pipeline was successful
2024-05-15 13:15:14 +02:00
7c2bc0f623 build(deps): update dependency conventional-changelog-conventionalcommits to v8
Some checks failed
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline failed
2024-05-04 00:02:30 +00:00
semantic-release-bot
10a4c8ea36 release(rc): v1.0.1-rc.9
## [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](28c7b9114b))
2024-04-12 12:43:42 +00:00
28c7b9114b build(deps): update dependency semantic-release to v23.0.8
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-04-12 12:41:50 +00:00
semantic-release-bot
8460428ac4 release(rc): v1.0.1-rc.8
## [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](38cf6dbfc2))
2024-04-12 12:39:28 +00:00
38cf6dbfc2 build(deps): update dependency @semantic-release/release-notes-generator to v13
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-27 00:03:11 +00:00
semantic-release-bot
88b140c072 release(rc): v1.0.1-rc.7
## [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](ff8d5cd4b3))
2024-03-23 23:21:30 +00:00
ff8d5cd4b3 build(deps): update dependency semantic-release to v23.0.5
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-23 23:20:42 +00:00
semantic-release-bot
b59f819aa0 release(rc): v1.0.1-rc.6
## [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](6148fb1dcc))
2024-03-23 23:18:03 +00:00
6148fb1dcc build(deps): update dependency @semantic-release/commit-analyzer to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-03-19 00:03:04 +00:00
semantic-release-bot
67ad1cb0bc release(rc): v1.0.1-rc.5
## [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](1c49da97cc))
2024-03-17 11:36:19 +00:00
1c49da97cc build(deps): update dependency @semantic-release/npm to v12
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024-03-17 11:34:55 +00:00
semantic-release-bot
736b16ce24 release(rc): v1.0.1-rc.4
## [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)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.4 ([f45e6e5](f45e6e52ed))
2024-03-17 11:29:31 +00:00
f45e6e52ed build(deps): update dependency semantic-release to v23.0.4
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-03-17 00:03:08 +00:00
semantic-release-bot
08f249374b release(rc): v1.0.1-rc.3
## [1.0.1-rc.3](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.2...v1.0.1-rc.3) (2024-03-16)

### Build system and dependencies

* **deps:** update dependency semantic-release to v23.0.3 ([6cc61a8](6cc61a86ef))
2024-03-16 00:06:24 +00:00
6cc61a86ef build(deps): update dependency semantic-release to v23.0.3
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/release Pipeline was successful
2024-03-16 00:03:52 +00:00
semantic-release-bot
514b6e67a4 release(rc): v1.0.1-rc.2
## [1.0.1-rc.2](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.1...v1.0.1-rc.2) (2024-03-02)

### Continuous Integrations

* **renovate:** add Renovate bot configuration ([cf9d970](cf9d97099d))

### Build system and dependencies

* **deps:** update all non-major dependencies ([efd1b2b](efd1b2b347))
* **deps:** update all non-major dependencies ([b8a9834](b8a9834910))
* **deps:** update dependency semantic-release to v23 ([1223d34](1223d341e2))
2024-03-02 15:17:25 +00:00
6cecc1e4d0 Merge pull request 'build(deps): update all non-major dependencies' (#5) from renovate-all-minor-patch into devel
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
Reviewed-on: #5
2024-03-02 16:17:00 +01:00
efd1b2b347 build(deps): update all non-major dependencies
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
2024-03-02 00:02:55 +00:00
b64ad3e798 Merge pull request 'build(deps): update all non-major dependencies' (#2) from renovate-all-minor-patch into devel
Reviewed-on: #2
2024-02-29 00:54:16 +01:00
b8a9834910 build(deps): update all non-major dependencies 2024-02-28 23:54:06 +00:00
2d760a1b34 Merge pull request 'build(deps): update dependency semantic-release to v23' (#3) from renovate-major-all-major into devel
Reviewed-on: #3
2024-02-29 00:50:49 +01:00
1223d341e2 build(deps): update dependency semantic-release to v23 2024-02-28 23:46:50 +00:00
cf9d97099d
ci(renovate): add Renovate bot configuration 2024-02-29 00:21:08 +01:00
semantic-release-bot
ca9370d247 release(rc): v1.0.1-rc.1
## [1.0.1-rc.1](https://git.ext.icikowski.pl/go/sets/compare/v1.0.0...v1.0.1-rc.1) (2023-11-04)

### Continuous Integrations

* **init:** add initial CI configuration ([0ac2547](0ac25476ab))
2023-11-04 20:18:26 +00:00
1bda6671dd Merge pull request 'Add Woodpecker CI support' (#1) from ci into devel
All checks were successful
ci/woodpecker/push/release Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
Reviewed-on: #1
2023-11-04 21:17:39 +01:00
0ac25476ab
ci(init): add initial CI configuration
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
2023-11-04 20:36:50 +01:00
14 changed files with 8577 additions and 16 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.vscode/*
node_modules/*

152
.releaserc.json Normal file
View File

@ -0,0 +1,152 @@
{
"branches": [
{
"name": "main",
"channel": "stable",
"prerelease": false
},
{
"name": "devel",
"channel": "rc",
"prerelease": "rc"
}
],
"plugins": [
[
"@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"releaseRules": [
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": false
},
{
"type": "style",
"release": false
},
{
"type": "refactor",
"release": "patch"
},
{
"type": "perf",
"release": "minor"
},
{
"type": "test",
"release": "patch"
},
{
"type": "build",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "revert",
"release": "patch"
},
{
"type": "release",
"release": false
}
],
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
}
}
],
[
"@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "docs",
"hidden": true
},
{
"type": "refactor",
"section": "Refactoring",
"hidden": false
},
{
"type": "perf",
"section": "Performance Improvements",
"hidden": false
},
{
"type": "test",
"section": " Tests",
"hidden": false
},
{
"type": "ci",
"section": "Continuous Integrations",
"hidden": false
},
{
"type": "chore",
"hidden": true
},
{
"type": "revert",
"section": "Reverts",
"hidden": false
},
{
"type": "release",
"hidden": true
},
{
"type": "build",
"section": "Build system and dependencies",
"hidden": false
}
]
}
}
],
[
"@semantic-release/changelog", {
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/npm", {
"npmPublish": false
}
],
["@saithodev/semantic-release-gitea", {
"giteaUrl": "https://git.ext.icikowski.pl"
}],
[
"@semantic-release/git", {
"assets": ["CHANGELOG.md","package.json", "package-lock.json"],
"message": "release(${nextRelease.channel}): v${nextRelease.version}\n\n${nextRelease.notes}"
}
]
],
"preset": "conventionalcommits"
}

38
.renovaterc.json Normal file
View File

@ -0,0 +1,38 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>renovate/renovate"
],
"packageRules": [
{
"groupName": "all non-major dependencies",
"groupSlug": "all-minor-patch",
"matchPackagePatterns": [
"*"
],
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": false
},
{
"groupName": "all major dependencies",
"groupSlug": "all-major",
"matchPackagePatterns": [
"*"
],
"matchUpdateTypes": [
"major"
],
"automerge": false
}
],
"ignoreDeps": [],
"postUpdateOptions": [
"gomodTidy",
"gomodUpdateImportPaths"
]
}

13
.woodpecker/.release.yml Normal file
View File

@ -0,0 +1,13 @@
when:
- event: push
evaluate: '(CI_COMMIT_BRANCH == "devel" && not (CI_COMMIT_MESSAGE startsWith "release")) || (CI_COMMIT_BRANCH == "main" && not (CI_COMMIT_MESSAGE startsWith "release(stable)"))'
steps:
semantic-release:
image: node:latest
secrets:
- gitea_token
- git_credentials
commands:
- npm i
- npm run release

10
.woodpecker/.test.yml Normal file
View File

@ -0,0 +1,10 @@
when:
- event: [push, pull_request]
branch: devel
evaluate: 'not (CI_COMMIT_MESSAGE startsWith "release")'
steps:
test:
image: golang:1.22-alpine
commands:
- go test -v ./...

99
CHANGELOG.md Normal file
View File

@ -0,0 +1,99 @@
## [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)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.4 ([f45e6e5](https://git.ext.icikowski.pl/go/sets/commit/f45e6e52ede310174421a6fe7f21f126aaaa24a4))
## [1.0.1-rc.3](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.2...v1.0.1-rc.3) (2024-03-16)
### Build system and dependencies
* **deps:** update dependency semantic-release to v23.0.3 ([6cc61a8](https://git.ext.icikowski.pl/go/sets/commit/6cc61a86efc2a46f6c0d98517916011cfcdac444))
## [1.0.1-rc.2](https://git.ext.icikowski.pl/go/sets/compare/v1.0.1-rc.1...v1.0.1-rc.2) (2024-03-02)
### Continuous Integrations
* **renovate:** add Renovate bot configuration ([cf9d970](https://git.ext.icikowski.pl/go/sets/commit/cf9d97099df59f7906610100963320613091449b))
### Build system and dependencies
* **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 to v23 ([1223d34](https://git.ext.icikowski.pl/go/sets/commit/1223d341e284b641fc35e6d247616dcaaf760a90))
## [1.0.1-rc.1](https://git.ext.icikowski.pl/go/sets/compare/v1.0.0...v1.0.1-rc.1) (2023-11-04)
### Continuous Integrations
* **init:** add initial CI configuration ([0ac2547](https://git.ext.icikowski.pl/go/sets/commit/0ac25476ab2bee29255cf3ee5172a0848a67ebdf))

5
README.md Normal file
View 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.

View File

@ -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()

2
go.mod
View File

@ -2,7 +2,7 @@ module pkg.icikowski.pl/sets
go 1.20
require github.com/stretchr/testify v1.8.4
require github.com/stretchr/testify v1.9.0
require (
github.com/davecgh/go-spew v1.1.1 // indirect

4
go.sum
View File

@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

8219
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/*
Sets-related types & functions
Sets and useful functions for working with them.
*/
package sets

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"private": true,
"name": "sets",
"version": "1.1.0-rc.1",
"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": "^12.0.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^12.0.0",
"@semantic-release/release-notes-generator": "^13.0.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"semantic-release": "^23.0.0"
}
}

19
set.go
View File

@ -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()