当前位置:网站首页>[go] introduction to exp
[go] introduction to exp
2022-06-09 11:01:00 【alwaysrun】
List of articles
go Official experimental package
https://pkg.go.dev/golang.org/x/exp Contains many useful packages ; adopt go get golang.org/x/exp Easily accessible . exp package
exp The package is experimental , It may be merged into the main branch or discarded ; And there is no guarantee that Go1 The compatibility of .
constraints
constraints Some useful generic parameter constraint sets are defined in the package :
- Complex: The plural
- Float: Floating point numbers
- Integer: Integers
- Signed: Signed integers
- Unsigned: Unsigned integer
- Ordered: Numbers and strings
maps
maps Some useful methods are defined in , Used for processing map And type :
- Clear(m): Empty m Items in ;
- Clone(m): return m A copy of ( Both keys and values are shallow copies );
- Copy(dst, src): hold src The entry in is appended to dst in ( The key with the same name is overwritten );
- DeleteFunc(m, del func(K, V) bool): Delete entries that meet the criteria ;
- Equal(m1, m2): Compare the two map Whether it is equal or not
- EqualFunc(m1, m2, eq func(V1, V2) bool): Compare two according to the conditions map Whether it is equal or not ;
- Keys(m)[]K: return map All the keys in ( Uncertain order );
- Values(m)[]V: return map All the values in ( Uncertain order );
rand
rand Package to achieve a pseudo-random number generator :
- ExpFloat64() float64: Returns... In exponential form (0, +math.MaxFloat64] number of rooms ;
- Float32() float32: return [0.0,1.0) Inter floating point number ;
- Float64() float64: return [0.0,1.0) Inter floating point number ;
- Int() int: Returns a nonnegative integer ;
- Int31() int32: Returns nonnegative 31 An integer ;
- Int31n(n int32) int32: return [0,n) The whole number between ;
- Int63() int64: Returns a nonnegative integer ;
- Int63n(n int64) int64: Returns nonnegative 63 An integer ;
- Intn(n int) int: return [0,n) The whole number between ;
- NormFloat64() float64: Returns the normal distribution [-math.MaxFloat64, +math.MaxFloat64] Number between ;
- Perm(n int) []int: Return contains [0,n) Slice all the numbers ( The order is random );
- Read(p []byte) (n int, err error): fill p Is a random number ;
- Seed(seed uint64): Set random seeds ;
- Shuffle(n int, swap func(i, j int)): Shuffle ( according to i,j Exchange elements );
- Uint32() uint32: return 32 Bit unsigned integer ;
- Uint64() uint64: return 64 Bit unsigned integer ;
func main() {
numbers := []byte("12345")
letters := []byte("ABCDE")
// Shuffle numbers, swapping corresponding entries in letters at the same time.
rand.Shuffle(len(numbers), func(i, j int) {
numbers[i], numbers[j] = numbers[j], numbers[i]
letters[i], letters[j] = letters[j], letters[i]
})
for i := range numbers {
fmt.Printf("%c: %c\n", letters[i], numbers[i])
}
}
slices
slices Some useful methods for processing slices are defined in :
- BinarySearch(x []E, target E) (int, bool): Bisect the slices in ascending order ( If you find , Return its subscript ; Otherwise, it is the position where it should be inserted );
- BinarySearchFunc(x []E, target E, cmp func(E, E) int) (int, bool): Binary search in the specified way ;
- Clip(s S) S: tailoring ( Remove excess unused space );
- Clone(s S) S: Copy slices ( Elements use light copies );
- Compact(s S) S: Return compression ( Remove adjacent identical elements , Leave only one copy ) After slicing , The original slice has also been modified ( But the length has not changed );
- CompactFunc(s S, eq func(E, E) bool) S: Compress in the specified way ;
- Compare(s1, s2 []E) int: Compare ;
- CompareFunc(s1 []E1, s2 []E2, cmp func(E1, E2) int) int: Compare ;
- Contains(s []E, v E) bool: Whether there is ;
- Delete(s S, i, j int) S: remove [i:j) Inter element ;
- Equal(s1, s2 []E) bool: Whether it is equal or not ;
- EqualFunc(s1 []E1, s2 []E2, eq func(E1, E2) bool) bool: Whether it is equal or not ;
- Grow(s S, n int) S: Add capacity ;
- Index(s []E, v E) int: return v The first index to appear , No return found -1;
- IndexFunc(s []E, f func(E) bool) int: Find... As specified ;
- Insert(s S, i int, v …E) S: stay i Position insert element ;
- IsSorted(x []E) bool: Determine whether to sort ;
- IsSortedFunc(x []E, less func(a, b E) bool) bool: Determine whether to sort ;
- Sort(x []E): Sort ( Ascending );
- SortFunc(x []E, less func(a, b E) bool): Sort as specified ;
- SortStableFunc(x []E, less func(a, b E) bool): Stable sequencing ;
func deleteElem() {
s := []int{
1, 2, 3, 4, 5, 6, 7}
fmt.Println("before:", s)
s2 := slices.Delete(s, 0, 1)
fmt.Println("ori:", s)
fmt.Println("del:", s2)
}
// before: [1 2 3 4 5 6 7]
// ori: [2 3 4 5 6 7 7]
// del: [2 3 4 5 6 7]
边栏推荐
- 深耕十年,玄武云科技终于稳坐快消SaaS龙头宝座
- 这6种开源协议(GPL,LGPL,BSD,MIT,Apache)
- WebAssembly 2022调查来啦
- Micronet: image recognition with very low flop
- 叁拾肆- sklearn 根据样本对文本情绪进行分类
- go-zero 微服务实战系列(二、服务拆分)
- Thirty seven - JS tried fractal graphics on canvas (I) drew an ordinary box graph
- Recursive and non recursive implementation of quick sorting of interview questions
- 面试题快速排序 递归和非递归实现
- Web development exchange, web development example tutorial
猜你喜欢

Web development exchange, web development example tutorial
![[optics] double slit interference with GUI Based on MATLAB simulation light](/img/9a/0c33e71111b878e48ef3a1cc77ab3c.png)
[optics] double slit interference with GUI Based on MATLAB simulation light

Lua调用原理展示(Lua堆栈)

Go zero micro Service Practice Series (II. Service splitting)

投稿开奖丨轻量应用服务器征文活动(4月)奖励公布

Harbor正确密码登录不上去

Interaction between C language and Lua (practice 2)

Thirty one - the number of mongodb links in nodejs simple proxy pool (combined) exploded

InfoQ geek media's 15th anniversary solicitation 𞓜 migration of Eureka to Nacos: dual registration and dual subscription model

【模型部署与业务落地】AI 框架部署方案之模型转换
随机推荐
Forty five - regular expressions (? =pattern) and (?! pattern)
论文阅读 (54):DeepFool: A Simple and Accurate Method to Fool Deep Neural Networks
Flutter sort the contacts alphabetically and click slide
Go zero micro Service Practice Series (II. Service splitting)
Is it safe to open an account at flush
Lua call principle demonstration (Lua stack)
Forty four - wechat applet canvas unlocking and spring physical effect animation
C语言与Lua的交互(实践二)
33 - nodejs simple proxy pool (it's estimated that it's over) the painful experience of using proxy by SuperAgent and the need to be careful
Thirty eight JS tried fractal graphics on canvas (II) tried mountain building, painted mountains and the basis of angular geometry
[model deployment and business implementation] model transformation of AI framework deployment scheme
Le nombre de liens mongodb pour le pool d'agents simples de nodejs a explosé
flutter 按字母 排序 通讯录并点击滑动
投稿开奖丨轻量应用服务器征文活动(4月)奖励公布
【tgcalls】跟踪调试calls的manager们 2
【水果识别】基于形态学实现水果识别含Matlab源码
太神奇的 SQL 查询经历,group by 慢查询优化!
[image enhancement] image enhancement based on sparse representation and regularization with matlab code
"When you are no longer a programmer, many things will get out of control" -- a dialogue with SUSE CTO, the world's largest independent open source company
Application of ebpf in cloud native environment