Compare commits

..

No commits in common. "c9c126231308add668246622d0706e63b101c848" and "fc082a7524e665ba33b052e3ab6ba47e7d4659e6" have entirely different histories.

14 changed files with 16 additions and 8577 deletions

2
.gitignore vendored
View File

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

View File

@ -1,152 +0,0 @@
{
"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"
}

View File

@ -1,38 +0,0 @@
{
"$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"
]
}

View File

@ -1,13 +0,0 @@
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

View File

@ -1,10 +0,0 @@
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 ./...

View File

@ -1,99 +0,0 @@
## [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))

View File

@ -1,5 +0,0 @@
# `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 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()

2
go.mod
View File

@ -2,7 +2,7 @@ module pkg.icikowski.pl/sets
go 1.20 go 1.20
require github.com/stretchr/testify v1.9.0 require github.com/stretchr/testify v1.8.4
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect 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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 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/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

8219
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,18 +0,0 @@
{
"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" "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()