utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package utils 提供文件查找等内部通用工具。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFirstFileInDirs

func FindFirstFileInDirs(dirs []string, targetFiles ...string) (string, error)

func ReportFormatFromOutput added in v0.1.2

func ReportFormatFromOutput(output string) (string, bool)

ReportFormatFromOutput 根据报告输出路径扩展名推断报告格式。

func SamePath added in v0.1.3

func SamePath(left, right string) bool

SamePath 判断两个文件路径是否指向同一文件。先按绝对路径与路径清理结果比较, 不相等时再尝试解析符号链接;任一环节出错返回 false。

Types

type LRU added in v0.1.1

type LRU[K comparable, V any] struct {
	// contains filtered or unexported fields
}

LRU 是一个并发安全的最近最少使用缓存。 缓存同时受条目数量和可选总权重限制;条目淘汰后会在缓存锁释放后调用 onEvict。

func NewLRU added in v0.1.1

func NewLRU[K comparable, V any](capacity int, onEvict func(K, V)) *LRU[K, V]

NewLRU 创建只按条目数量限制的 LRU 缓存。

func NewWeightedLRU added in v0.1.1

func NewWeightedLRU[K comparable, V any](capacity int, maxWeight int64, onEvict func(K, V), canEvict ...func(K, V) bool) *LRU[K, V]

NewWeightedLRU 创建按条目数量和总权重限制的 LRU 缓存。 maxWeight 小于等于 0 表示不启用权重限制。可选的 canEvict 只用于暂时保护条目。

func (*LRU[K, V]) Add added in v0.1.1

func (c *LRU[K, V]) Add(key K, value V)

Add 添加一个权重为 1 的条目。

func (*LRU[K, V]) AddWeighted added in v0.1.1

func (c *LRU[K, V]) AddWeighted(key K, value V, weight int64)

AddWeighted 添加一个带权重的条目;负权重按 0 处理。

func (*LRU[K, V]) Get added in v0.1.1

func (c *LRU[K, V]) Get(key K) (V, bool)

Get 获取 key 对应的值,并将该条目提升为最近使用条目。

func (*LRU[K, V]) Len added in v0.1.1

func (c *LRU[K, V]) Len() int

Len 返回当前缓存中的条目数量。

func (*LRU[K, V]) Trim added in v0.1.1

func (c *LRU[K, V]) Trim()

Trim 主动按当前容量和权重限制清理可淘汰条目。 被淘汰策略保护的条目会暂时保留,待之后再次调用 Trim 时处理。

func (*LRU[K, V]) Weight added in v0.1.1

func (c *LRU[K, V]) Weight() int64

Weight 返回当前缓存条目的总权重。

Jump to

Keyboard shortcuts

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