halvector

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 7 Imported by: 3

README

HAL vector

HTTP Accept-Language vector parser. Based on accept-language-parser library, but based on vector parser instead of regexp due to performance reasons and reduce pointers policy.

Usage

src := "fr-CA,fr;q=0.2,en-US;q=0.6,en;q=0.4,*;q=0.5"
vec := halvector.Acquire()
defer halvector.Release(vec)
_ = vec.ParseStr(src)
vec.Sort().Root().Each(func(idx int, node *vector.Node) {
	print(idx, ":")
	println("code:", node.GetString("code"))
	println("script:", node.GetString("script"))
	println("region:", node.GetString("region"))
	q, _ := node.Get("quality").Float()
	println("quality:", q)
})

Output:

0 :
code: fr
script: 
region: CA
quality: +1.000000e+000
1 :
code: en
script: 
region: US
quality: +6.000000e-001
2 :
code: *
script: 
region: 
quality: +5.000000e-001
3 :
code: en
script: 
region: 
quality: +4.000000e-001
4 :
code: fr
script: 
region: 
quality: +2.000000e-001

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyParts = errors.New("entry contains too many parts")
)

Functions

func Release

func Release(vec *Vector)

Release puts vector back to default pool instance.

func ReleaseNC added in v1.0.6

func ReleaseNC(vec *Vector)

ReleaseNC puts vector back to pool with enforced no-clear flag.

Types

type Helper added in v1.0.5

type Helper struct{}

func (Helper) Beautify added in v1.0.5

func (Helper) Beautify(w io.Writer, node *vector.Node) error

func (Helper) Indirect added in v1.0.5

func (Helper) Indirect(p *vector.Byteptr) []byte

func (Helper) Marshal added in v1.0.5

func (Helper) Marshal(w io.Writer, node *vector.Node) error

type Pool

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

func (*Pool) Get

func (p *Pool) Get() *Vector

Get old vector from the pool or create new one.

func (*Pool) Put

func (p *Pool) Put(vec *Vector)

Put vector back to the pool.

type Vector

type Vector struct {
	vector.Vector
	// contains filtered or unexported fields
}

func Acquire

func Acquire() *Vector

Acquire returns vector from default pool instance.

func AcquireWithLimit added in v1.0.4

func AcquireWithLimit(limit int) *Vector

AcquireWithLimit returns vector with given limit.

func NewVector

func NewVector() *Vector

func (*Vector) Parse

func (vec *Vector) Parse(s []byte) error

func (*Vector) ParseCopy

func (vec *Vector) ParseCopy(s []byte) error

func (*Vector) ParseCopyStr

func (vec *Vector) ParseCopyStr(s string) error

ParseCopyStr copies source string and parse it. DEPRECATED: use ParseCopyString instead.

func (*Vector) ParseCopyString added in v1.0.8

func (vec *Vector) ParseCopyString(s string) error

func (*Vector) ParseStr

func (vec *Vector) ParseStr(s string) error

ParseStr parses source string. DEPRECATED: use ParseString instead.

func (*Vector) ParseString added in v1.0.8

func (vec *Vector) ParseString(s string) error

func (*Vector) Reset added in v1.0.4

func (vec *Vector) Reset()

func (*Vector) SetLimit added in v1.0.4

func (vec *Vector) SetLimit(limit int) *Vector

SetLimit setups hard of nodes. All entities over the limit will ignore. See BenchmarkLimit() for explanation.

func (*Vector) Sort

func (vec *Vector) Sort() *Vector

Jump to

Keyboard shortcuts

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