util

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: LGPL-2.1 Imports: 1 Imported by: 0

Documentation

Overview

Package util 一些工具类与函数。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache2Iface

func Cache2Iface[T any](fi IfaceCache) T

Cache2Iface 接口存储器转换为接口

func Zero

func Zero[T any]() T

Zero 创建零值

Types

type Face

type Face[T any] struct {
	Iface T
	Cache IfaceCache
}

Face 面,用于存储接口与其存储器,接口可用于断言转换类型,存储器可用于转换为接口

func NewFace

func NewFace[T any](iface T) Face[T]

NewFace 创建面

func NewFacePair

func NewFacePair[T, C any](iface T, cache C) Face[T]

NewFacePair 创建面,同时传入接口与其存储器

func (*Face[T]) IsNil

func (f *Face[T]) IsNil() bool

IsNil 是否为空

type FaceAny

type FaceAny = Face[any]

FaceAny any面

type IfaceCache

type IfaceCache [2]unsafe.Pointer

IfaceCache 接口存储器,因为Golang原生的接口转换性能较差,所以在某些性能要求较高的场景(例如瞬时演算)下,需要尽量较少接口转换。 目前可用的优化方案是,在编码时明确知晓接口类型时,可以将接口转换为[2]unsafe.Pointer保存接口,使用时再转换为接口即可。 为了使用方便,本包提供了一套方法用于支持此类需求,注意不安全,在明确了解此功能时再使用。

var NilIfaceCache IfaceCache

NilIfaceCache 空接口存储器

func Iface2Cache

func Iface2Cache[T any](i T) IfaceCache

Iface2Cache 接口转换为接口存储器

Directories

Path Synopsis
Package container 实现了一种特殊的链表,可以在遍历时在任意位置添加或删除元素,递归添加或删除元素时仍然能正常工作,但是需要GC支持,主要用于ec包内部。
Package container 实现了一种特殊的链表,可以在遍历时在任意位置添加或删除元素,递归添加或删除元素时仍然能正常工作,但是需要GC支持,主要用于ec包内部。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL