1 Star 0 Fork 0

sy_183 / go-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
unsafe.go 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
package unsafe
import "unsafe"
type iter struct {
key unsafe.Pointer
elem unsafe.Pointer
t unsafe.Pointer
h unsafe.Pointer
buckets unsafe.Pointer
bptr unsafe.Pointer
overflow unsafe.Pointer
oldoverflow unsafe.Pointer
startBucket uintptr
offset uint8
wrapped bool
B uint8
i uint8
bucket uintptr
checkBucket uintptr
}
type Iter[K comparable, V any] iter
//go:linkname mapiterinit runtime.mapiterinit
func mapiterinit(t unsafe.Pointer, h unsafe.Pointer, it *iter)
//go:linkname mapiternext runtime.mapiternext
func mapiternext(it *iter)
func NewIter[K comparable, V any](m map[K]V) *Iter[K, V] {
mi := any(m)
hi := new(iter)
mapiterinit(*(*unsafe.Pointer)(unsafe.Pointer(&mi)), *(*unsafe.Pointer)(unsafe.Pointer(&m)), hi)
return (*Iter[K, V])(hi)
}
func (i *Iter[K, V]) Next() {
mapiternext((*iter)(i))
}
func (i *Iter[K, V]) Has() bool {
return i.key != nil
}
func (i *Iter[K, V]) Key() K {
return *(*K)(i.key)
}
func (i *Iter[K, V]) Value() V {
return *(*V)(i.elem)
}
1
https://gitee.com/sy_183/go-common.git
git@gitee.com:sy_183/go-common.git
sy_183
go-common
go-common
v1.0.4

搜索帮助