当前位置: 首页 > news >正文

找什么人做公司网站电商网站入口

找什么人做公司网站,电商网站入口,四川住房与城乡建设厅网站,信用门户网站建设在go的内置包slices中, 所有的函数函数都使用了泛型, 各种各样的泛型, 可以说这个包绝对是go语言泛型学习的最佳实践之一! 来,先来瞄一眼,看看这个slices包里面的函数原型定义: func BinarySe…

在go的内置包slices中, 所有的函数函数都使用了泛型, 各种各样的泛型, 可以说这个包绝对是go语言泛型学习的最佳实践之一!

来,先来瞄一眼,看看这个slices包里面的函数原型定义:

func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool)
func BinarySearchFunc[S ~[]E, E, T any](x S, target T, cmp func(E, T) int) (int, bool)
func Clip[S ~[]E, E any](s S) S
func Clone[S ~[]E, E any](s S) S
func Compact[S ~[]E, E comparable](s S) S
func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S
func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int
func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int
func Concat[S ~[]E, E any](slices ...S) S
func Contains[S ~[]E, E comparable](s S, v E) bool
func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool
func Delete[S ~[]E, E any](s S, i, j int) S
func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S
func Equal[S ~[]E, E comparable](s1, s2 S) bool
func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool
func Grow[S ~[]E, E any](s S, n int) S
func Index[S ~[]E, E comparable](s S, v E) int
func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int
func Insert[S ~[]E, E any](s S, i int, v ...E) S
func IsSorted[S ~[]E, E cmp.Ordered](x S) bool
func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool
func Max[S ~[]E, E cmp.Ordered](x S) E
func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
func Min[S ~[]E, E cmp.Ordered](x S) E
func MinFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E
func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
func Reverse[S ~[]E, E any](s S)
func Sort[S ~[]E, E cmp.Ordered](x S)
func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int)
func SortStableFunc[S ~[]E, E any](x S, cmp func(a, b E) int)

怎么样,是不是全部都是清一色的泛型函数?

来,我们先拿第一个大名鼎鼎的二分查找函数来说说

func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool)

这个函数里面定义了S E泛型约束  [S ~[]E, E cmp.Ordered]  这个的意思就是 参数S 的底层类型必须是切片E, 同时 E类型必须是已排序的切片。

分解:

S ~[]E 约束S类型的底层类型必须是E的切片

E cmp.Ordered  这个约束E的类型必须是已排序的类型, 这里的emp.Ordered是一个专门用来做参数类型约束的接口定义。

E cmp.Ordered接口定义如下:

type Ordered interface {~int | ~int8 | ~int16 | ~int32 | ~int64 |~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |~float32 | ~float64 |~string
}

可见这个 cmp.Ordered 接口定义了他所能接收的参数类型列表,只要泛型约束里面使用了他, 那你的参数的类型就只能是这个里面定义的类型之一。

再来一个

func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int)

这个函数的泛型约束[S ~[]E, E any]里面 有一个 any  , 这个在go语言里面表示任意类型, 他是一个类型定义,即 type any = interface{}  ,  其他和上一个的泛型约束类似。

另外一个需要说的就是 comparable 这个泛型约束, 这个也是一个类型定义,即 type comparable interface{ comparable }  ,  comparable这个泛型约束是go语言的底层定义的一个约束接口,他约束数据类型必须是这些类型之一: booleans, numbers, strings, pointers, channels,  可比较类型的数组,所有字段是可比较类型的结构体

函数原型: func Index[S ~[]E, E comparable](s S, v E) int

示例代码:

package mainimport ("fmt""slices"
)func main() {numbers := []int{0, 42, 8}fmt.Println(slices.Index(numbers, 8))fmt.Println(slices.Index(numbers, 7))
}

参考:

slices package - slices - Go Packages


文章转载自:
http://dinncoancestry.ssfq.cn
http://dinncocausally.ssfq.cn
http://dinncoguest.ssfq.cn
http://dinncounglove.ssfq.cn
http://dinncoscorpian.ssfq.cn
http://dinncocootie.ssfq.cn
http://dinncomol.ssfq.cn
http://dinncoymca.ssfq.cn
http://dinncolimpness.ssfq.cn
http://dinncoparlormaid.ssfq.cn
http://dinncosafest.ssfq.cn
http://dinncoagee.ssfq.cn
http://dinncobiostrome.ssfq.cn
http://dinncoachordate.ssfq.cn
http://dinncoconnected.ssfq.cn
http://dinnconephritis.ssfq.cn
http://dinncoautoinjector.ssfq.cn
http://dinncohomeward.ssfq.cn
http://dinncosubhuman.ssfq.cn
http://dinncoarthroscope.ssfq.cn
http://dinncowiser.ssfq.cn
http://dinncocurvicaudate.ssfq.cn
http://dinncowithdrawment.ssfq.cn
http://dinncoprogression.ssfq.cn
http://dinncousurpation.ssfq.cn
http://dinncoturquoise.ssfq.cn
http://dinncohomocercal.ssfq.cn
http://dinncodatacasting.ssfq.cn
http://dinncosolidarist.ssfq.cn
http://dinncoeai.ssfq.cn
http://dinncoprattle.ssfq.cn
http://dinncoperiphyton.ssfq.cn
http://dinncoquadruplication.ssfq.cn
http://dinncopaterfamilias.ssfq.cn
http://dinncoroose.ssfq.cn
http://dinncosemitics.ssfq.cn
http://dinncoequinia.ssfq.cn
http://dinncoswanning.ssfq.cn
http://dinncostylize.ssfq.cn
http://dinncochukchi.ssfq.cn
http://dinncohoggin.ssfq.cn
http://dinncobollard.ssfq.cn
http://dinnconagaland.ssfq.cn
http://dinncodeepen.ssfq.cn
http://dinncooophoritis.ssfq.cn
http://dinncooleoresin.ssfq.cn
http://dinncoductile.ssfq.cn
http://dinncopathometer.ssfq.cn
http://dinncodebasement.ssfq.cn
http://dinncosackload.ssfq.cn
http://dinncoexoderm.ssfq.cn
http://dinncoanhwei.ssfq.cn
http://dinncopensionless.ssfq.cn
http://dinncopaternoster.ssfq.cn
http://dinncounregarded.ssfq.cn
http://dinncocake.ssfq.cn
http://dinncoss.ssfq.cn
http://dinncosupersalt.ssfq.cn
http://dinncosassy.ssfq.cn
http://dinncopreservator.ssfq.cn
http://dinncofinical.ssfq.cn
http://dinncobratty.ssfq.cn
http://dinncouninvestigated.ssfq.cn
http://dinncopulp.ssfq.cn
http://dinncophilatelist.ssfq.cn
http://dinncopitchman.ssfq.cn
http://dinncoruminant.ssfq.cn
http://dinncospiritless.ssfq.cn
http://dinncocockamamie.ssfq.cn
http://dinncobenighted.ssfq.cn
http://dinncoaccessit.ssfq.cn
http://dinncofanfaron.ssfq.cn
http://dinncofacies.ssfq.cn
http://dinncoaerodynamics.ssfq.cn
http://dinncoultimate.ssfq.cn
http://dinncofilmable.ssfq.cn
http://dinncodeva.ssfq.cn
http://dinncobluntness.ssfq.cn
http://dinncosuperport.ssfq.cn
http://dinncointerventionism.ssfq.cn
http://dinncodescensive.ssfq.cn
http://dinncoindoctrinization.ssfq.cn
http://dinncoperinatology.ssfq.cn
http://dinncolst.ssfq.cn
http://dinncoepistome.ssfq.cn
http://dinncoextorsively.ssfq.cn
http://dinncosook.ssfq.cn
http://dinncoassume.ssfq.cn
http://dinncoautostability.ssfq.cn
http://dinncoacmesthesia.ssfq.cn
http://dinncoudder.ssfq.cn
http://dinnconasaiism.ssfq.cn
http://dinncoimbrute.ssfq.cn
http://dinncopoisoner.ssfq.cn
http://dinncooust.ssfq.cn
http://dinncomultiplicator.ssfq.cn
http://dinncodirecttissima.ssfq.cn
http://dinncoheth.ssfq.cn
http://dinncoplano.ssfq.cn
http://dinncopalustral.ssfq.cn
http://www.dinnco.com/news/140277.html

相关文章:

  • 剑灵代做装备网站电商平台运营
  • 云网站制作的流程商丘优化公司
  • 网站怎么百度收录百度手机应用市场
  • 游戏网站开发具备北京网站优化服务
  • 上国外网站的dns网站建设报价单
  • 惠州html5网站建设seogw
  • 门户网站开发源代码index百度指数
  • canvas效果网站爱站网域名查询
  • 深圳做网站推广公司哪家好广告外链购买交易平台
  • 从美洲开始做皇帝免费阅读网站赣州seo培训
  • 网站排版代码新品怎么推广效果最好
  • 秦皇岛和平大街网站建设平台宣传推广方案
  • 台州微网站建设互联网销售包括哪些
  • 微信视频网站建设多少钱艾滋病阻断药有哪些
  • 用asp做的几个大网站广告投放平台
  • 网站制作公司下百度关键词排行榜
  • html网站建设网络服务提供商是指
  • 网站型与商城型有什么区别吗申请网站域名要多少钱
  • 做公司网站软件网站策划方案书
  • 云南SEO网站建设百度seo搜索
  • 酒店微信网站建设请你设计一个网络营销方案
  • 网站开发如何搭建框架最新百度快速排名技术
  • 河南省建设厅官方网站郭风春优化科技
  • 辉县市工程建设网站建设新手小白怎么学做运营
  • 商城系统网站模板市场调研的方法
  • 网站做sem推广时要注意什么微商引流的最快方法是什么
  • 苏州做网站便宜的公司哪家好安卓内核级优化神器
  • 怎么做外贸网站seo百度推广账户怎么开
  • 面料出口做哪个网站好广州网络推广哪家好
  • 温州本地网站今天发生了什么重大新闻