Help us shape the future of Go! Take the 2026 Go Developer Survey

search

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package search 提供基于 Unicode 字符的文本索引与匹配能力。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexOfRunes

func IndexOfRunes(text, needle []rune, lps []int) int

IndexOfRunes 返回 needle 在 text 中首次出现的位置;未找到时返回 -1。

func RuneSearchTable

func RuneSearchTable(needle []rune) []int

RuneSearchTable 为 needle 构造 KMP 最长前缀表。

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder 构建 Index,并避免为每个文本段单独分配临时 map。

func NewBuilder

func NewBuilder(runCapacity int) *Builder

NewBuilder 创建一个可容纳 runCapacity 个文本段的构建器。

func (*Builder) Add

func (builder *Builder) Add(text string)

Add 添加一个文本段,并将其转为小写后纳入索引。

func (*Builder) Build

func (builder *Builder) Build() *Index

Build 返回完成后的索引;去重表仅保留在构建器中,不进入索引缓存。

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index 保存规范化后的文本段,并记录每个字符出现在哪些文本段中。

func (*Index) Candidates

func (index *Index) Candidates(value rune) []int

Candidates 返回包含指定字符的文本段索引。

func (*Index) Len

func (index *Index) Len() int

Len 返回索引中的文本段数量。

func (*Index) Run

func (index *Index) Run(run int) []rune

Run 返回指定文本段的小写字符序列。

func (*Index) Weight

func (index *Index) Weight() int64

Weight 估算索引占用的内存,用于带权重的缓存。

Jump to

Keyboard shortcuts

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