TopGit theo dõi scylladb/go-set trên GitHub trong nhóm Backend, đã đạt 814 sao. Type-safe, zero-allocation sets for Go
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Package set is a type-safe, zero-allocation port of the excellent package fatih/set. It contains sets for most of the basic types and you can generate sets for your own types with ease.
The library exposes a number of top level factory functions that can be used to create a specific instances of the set type you want to use. For example to create a set to store int you could do like this:
import "github.com/scylladb/go-set"
s := set.NewIntSet()
// use the set...
Usage
In every subpackage Set is the main set structure that holds all the data and methods used to working with the set.
func Difference
func Difference(set1 *Set, sets ...*Set) *Set
Difference returns a new set which contains items which are in in the first set
but not in the others.
func Intersection
func Intersection(sets ...*Set) *Set
Intersection returns a new set which contains items that only exist in all given
sets.
func New
func New(ts ...T) *Set
New creates and initializes a new Set.
func NewWithSize
func NewWithSize(size int) *Set
NewWithSize creates a new Set and gives make map a size hint.
func SymmetricDifference
func SymmetricDifference(s *Set, t *Set) *Set
SymmetricDifference returns a new set which s is the difference of items which
are in one of either, but not in both.
func Union
func Union(sets ...*Set) *Set
Union is the merger of multiple sets. It returns a new set with all the elements
present in all the sets that are passed.
func (*Set) Add
func (s *Set) Add(items ...T)
Add includes the specified items (one or more) to the Set. The underlying Set s
is modified. If passed nothing it silently returns.
func (*Set) Clear
func (s *Set) Clear()
Clear removes all items from the Set.
func (*Set) Copy
func (s *Set) Copy() *Set
Copy returns a new Set with a copy of s.
func (*Set) Each
func (s *Set) Each(f func(item T) bool)
Each traverses the items in the Set, calling the provided function for each Set
member. Traversal will continue until all items in the Set have been visited, or
if the closure returns false.
func (*Set) Has
func (s *Set) Has(items ...T) bool
Has looks for the existence of items passed. It returns false if nothing is
passed. For multiple items it returns true only if all of the items exist.
func (*Set) IsEmpty
func (s *Set) IsEmpty() bool
IsEmpty reports whether the Set is empty.
func (*Set) IsEqual
func (s *Set) IsEqual(t *Set) bool
IsEqual test whether s and t are the same in size and have the same items.
func (*Set) IsSubset
func (s *Set) IsSubset(t *Set) bool
IsSubset tests whether t is a subset of s.
func (*Set) IsSuperset
func (s *Set) IsSuperset(t *Set) bool
IsSuperset tests whether t is a superset of s.
func (*Set) List
func (s *Set) List() []T
List returns a slice of all items. There is also StringSlice() and IntSlice()
methods for returning slices of type string or int.
func (*Set) Merge
func (s *Set) Merge(t *Set)
Merge is like Union, however it modifies the current Set it's applied on with
the given t Set.
func (*Set) Pop
func (s *Set) Pop() T
Pop deletes and returns an item from the Set. The underlying Set s is modified.
If Set is empty, the zero value is returned.
func (*Set) Pop2
func (s *Set) Pop2() (T, bool)
Pop2 tries to delete and return an item from the Set. The underlying Set s is modified.
The second value is a bool that is true if the item existed in the set, and false if not.
If Set is empty, the zero value and false are returned.
func (*Set) Remove
func (s *Set) Remove(items ...T)
Remove deletes the specified items from the Set. The underlying Set s is
modified. If passed nothing it silently returns.
func (*Set) Separate
func (s *Set) Separate(t *Set)
Separate removes the Set items containing in t from Set s. Please aware that
it's not the opposite of Merge.
func (*Set) Size
func (s *Set) Size() int
Size returns the number of items in a Set.
func (*Set) String
func (s *Set) String() string
String returns a string representation of s
Performance
The improvement in performance by using concrete types over interface{} is notable. Below you will find benchmark results comparing type-safe sets to fatih/set counterparts for string, int64, int32, float64 and float32 on a local machine, Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz.
For code generation we use Google go_generics tool that we forked to provide bazel-free installation, to install run:
go get -u github.com/mmatczuk/go_generics/cmd/go_generics
Once you have go_generics installed properly you can regenerate the code using go generate in the top level directory.
Your custom types
If you have types that you would like to use but the are not amenable for inclusion in this library you can simply generate code on your own and put it in your package.
For example, to generate a set for SomeType in package sometypeset call:
./gen_set.sh SomeType sometypeset
this would generate a new directory sometypeset in current working directory.
If you think your addition belongs here we are open to accept pull requests.
License
Copyright (C) 2018 ScyllaDB
This project is distributed under the Apache 2.0 license. See the LICENSE file for details.
It contains software from:
github.com/fatih/set, licensed under the MIT license
scylladb/go-set thuộc nhóm Backend trên TopGit, cùng 3 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về scylladb/go-set ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/scylladb/go-set là nguồn chính thức.
scylladb/go-set có bao nhiêu sao?
scylladb/go-set có 814 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/scylladb/go-set. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
scylladb/go-set có phải mã nguồn mở không?
Có — scylladb/go-set phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/scylladb/go-set.
scylladb/go-set có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho scylladb/go-set. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
scylladb/go-set là gì?
scylladb/go-set (scylladb/go-set) là dự án Go trên GitHub. Theo mô tả gốc: Type-safe, zero-allocation sets for Go
scylladb/go-set so với các dự án Backend khác thế nào?
scylladb/go-set được TopGit xếp vào nhóm Backend, với 814 sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
go-set có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về go-set.