vector

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 13 Imported by: 11

README

Vector API

Provide Vector API for various parsers.

The main idea: many data interchange formats (such as JSON, XML, ...) stores data as a tree. Parsers of that formats reproduces that tree in a memory somehow or other.

This parser uses different way: it stores all parsed nodes (key-value pairs) in a special array (vector). That way protects from redundant memory allocations and reduces pointers. In fact, vector contains only two pointers (array of nodes and array of indexes). GC omits checking of that type of structs.

Comparison

All known parsers has the following data structures (approximately) to represent node value (key-value pair):

type Node struct {
	typ Type    // [null, object, array, string, number, true, false]
	obj Object  // one pointer to slice and N*2 pointers inside KeyValue struct, see below
	arr []*Node // one pointer for the slice and N pointers for each array item
	str string  // one pointer
}

type Object []KeyValue

type KeyValue struct {
	key string // one pointer
	val *Node  // one pointer to node
}

As you see during parsing will be produced tons of pointers. Better consider this with an example of JSON:

{
  "a": true,
  "b": {
    "c": "foo",
    "d": [
      5,
      3.1415,
      812.48927
    ]
  }
}

Majority of JSON parsers will build array of nodes like:

0 1 2 3 4 5 6 7
type: obj type: bool type: obj type: str type: arr type: num type: num type: num
key: "" key: "a" key: "" key: "c" key: "" key: "" key: "" key: ""
str: "" str: "" str: "" str: "foo" str: "" str: "" str: "" str: ""
num: 0 num: 0 num: 0 num: 0 num: 0 num: 5 num: 3.1415 num: 812.48927
bool: false bool: true bool: false bool: false bool: false bool: false bool: false bool: false
child: [*1, *2] child: [] child: [*3, *4] child: [] child: [*5, *6, *7] child: [] child: [] child: []

As you can see, independent of JSON node type, each parsed node contains at least 3 pointers:

  • key (string)
  • str (string)
  • child (slice of node pointers)

JSON vector has different approach and build the following array of nodes and index:

Vector:

0 1 2 3 4 5 6 7
type: obj type: bool type: obj type: str type: arr type: num type: num type: num
key pos: 0 key pos: 5 key pos: 18 key pos: 29 key pos: 45 key pos: 0 key pos: 0 key pos: 0
key len: 0 key len: 1 key len: 1 key len: 1 key len: 1 key len: 0 key len: 0 key len: 0
val pos: 0 val pos: 9 val pos: 0 val pos: 34 val pos: 0 val pos: 57 val pos: 64 val pos: 80
val len: 0 val len: 4 val len: 0 val len: 3 val len: 0 val len: 1 val len: 6 val len: 9
depth: 0 depth: 1 depth: 1 depth: 2 depth: 2 depth: 3 depth: 3 depth: 3
idx pos: 0 idx pos: 0 idx pos: 0 idx pos: 0 idx pos: 0 idx pos: 0 idx pos: 0 idx pos: 0
idx len: 2 idx len: 0 idx len: 2 idx len: 0 idx len: 3 idx len: 0 idx len: 0 idx len: 0

Index (Y-axis means depth, X-axis means position in the index):

X/Y 0 1 2
0 0 - -
1 1 2 -
2 3 4 -
3 5 6 7

Each node contains only int variables and therefore avoid escapes to heap at all. The whole vector contains only two pointers - nodes array and index matrix. GC checks it instantly. That way also allows parsing JSON with unlimited depths.

Documentation

Index

Constants

View Source
const FlagNoClear = 0

FlagNoClear disables clear step.

Variables

View Source
var (
	ErrEmptySrc     = errors.New("can't parse empty source")
	ErrShortSrc     = errors.New("source is too short to parse")
	ErrNotImplement = errors.New("method not implemented")
	ErrIncompatType = errors.New("incompatible type")
	ErrNotFound     = errors.New("node not found")
	ErrInternal     = errors.New("internal vector error")
	ErrNoHelper     = errors.New("helper not found")
	ErrUnparsedTail = errors.New("unparsed tail")
	ErrUnexpId      = errors.New("unexpected identifier")
	ErrUnexpEOF     = errors.New("unexpected end of file")
	ErrUnexpEOS     = errors.New("unexpected end of string")
)

Functions

This section is empty.

Types

type Byteptr

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

func (*Byteptr) Bytes

func (p *Byteptr) Bytes() []byte

func (*Byteptr) CheckBit added in v1.2.5

func (p *Byteptr) CheckBit(pos int) bool

func (*Byteptr) Init added in v1.2.5

func (p *Byteptr) Init(s []byte, offset, len int) *Byteptr

func (*Byteptr) InitRaw added in v1.2.5

func (p *Byteptr) InitRaw(addr uintptr, offset, len int) *Byteptr

func (*Byteptr) InitStr added in v1.2.5

func (p *Byteptr) InitStr(s string, offset, len int) *Byteptr

DEPRECATED: use InitString instead.

func (*Byteptr) InitString added in v1.2.5

func (p *Byteptr) InitString(s string, offset, len int) *Byteptr

func (*Byteptr) Len added in v1.2.5

func (p *Byteptr) Len() int

func (*Byteptr) Offset added in v1.2.5

func (p *Byteptr) Offset() int

func (*Byteptr) RawBytes

func (p *Byteptr) RawBytes() []byte

func (*Byteptr) RawString added in v1.2.5

func (p *Byteptr) RawString() string

func (*Byteptr) Reset

func (p *Byteptr) Reset()

func (*Byteptr) SetAddr added in v1.2.5

func (p *Byteptr) SetAddr(addr uintptr, cap int) *Byteptr

func (*Byteptr) SetBit added in v1.2.5

func (p *Byteptr) SetBit(pos int, value bool)

func (*Byteptr) SetLen added in v1.2.5

func (p *Byteptr) SetLen(len int) *Byteptr

func (*Byteptr) SetOffset added in v1.2.5

func (p *Byteptr) SetOffset(offset int) *Byteptr

func (*Byteptr) String

func (p *Byteptr) String() string

func (*Byteptr) TakeAddr added in v1.2.5

func (p *Byteptr) TakeAddr(s []byte) *Byteptr

func (*Byteptr) TakeStrAddr added in v1.2.5

func (p *Byteptr) TakeStrAddr(s string) *Byteptr

DEPRECATED: use TakeStringAddr instead.

func (*Byteptr) TakeStringAddr added in v1.2.5

func (p *Byteptr) TakeStringAddr(s string) *Byteptr

type Helper

type Helper interface {
	// Indirect convert byteptr to byte slice and apply custom logic.
	Indirect(*Byteptr) []byte
	// Beautify makes a beauty view of node.
	Beautify(io.Writer, *Node) error
	// Marshal serializes node.
	Marshal(io.Writer, *Node) error
}

Helper object interface.

type Index

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

Index represents nodes index matrix.

Contain indexes of nodes in the vector divided by depth. Y-axis means depth, X-axis means position in index.

func (*Index) GetRow

func (idx *Index) GetRow(depth int) []int

GetRow returns indices row registered at given depth.

func (*Index) Len

func (idx *Index) Len(depth int) int

Len returns length of index row registered on depth.

func (*Index) Register

func (idx *Index) Register(depth, i int) int

Register new index for given depth.

func (*Index) Reset

func (idx *Index) Reset(depth, offset int)

Reset rest of the index starting of given depth and offset in the tree.

type Interface

type Interface interface {
	SetHelper(helper Helper)

	Parse([]byte) error
	ParseCopy([]byte) error
	ParseStr(string) error
	ParseCopyStr(string) error

	Root() *Node
	RootByIndex(int) *Node
	RootTop() *Node
	Each(fn func(int, *Node))
	Exists(string) bool

	Get(...string) *Node
	GetObject(...string) *Node
	GetArray(...string) *Node
	GetBytes(...string) []byte
	GetString(...string) string
	GetBool(...string) bool
	GetFloat(...string) (float64, error)
	GetInt(...string) (int64, error)
	GetUint(...string) (uint64, error)

	GetPS(string, string) *Node
	GetObjectPS(string, string) *Node
	GetArrayPS(string, string) *Node
	GetBytesPS(string, string) []byte
	GetStringPS(string, string) string
	GetBoolPS(string, string) bool
	GetFloatPS(string, string) (float64, error)
	GetIntPS(string, string) (int64, error)
	GetUintPS(string, string) (uint64, error)

	Dot(string) *Node
	DotObject(string) *Node
	DotArray(string) *Node
	DotBytes(string) []byte
	DotString(string) string
	DotBool(string) bool
	DotFloat(string) (float64, error)
	DotInt(string) (int64, error)
	DotUint(string) (uint64, error)

	KeepPtr()

	Beautify(io.Writer) error
	Marshal(io.Writer) error

	ErrorOffset() int
	Prealloc(uint)
	Reset()
}

type Node

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

Node object.

func (*Node) Array

func (n *Node) Array() *Node

Array checks node is array and return it.

func (*Node) At

func (n *Node) At(idx int) *Node

At returns node from array at position idx.

May be used only for array nodes.

func (*Node) Beautify

func (n *Node) Beautify(w io.Writer) error

Beautify formats node in human-readable representation.

func (*Node) Bool

func (n *Node) Bool() bool

Bool returns value as boolean.

func (*Node) Bytes

func (n *Node) Bytes() []byte

Bytes returns value as bytes.

Allow only for [string, number, bool, attribute] types.

func (*Node) Children

func (n *Node) Children() []Node

Children returns list of children nodes.

func (*Node) ChildrenIndices added in v1.2.3

func (n *Node) ChildrenIndices() []int

ChildrenIndices returns list of indices of children nodes.

func (*Node) Depth

func (n *Node) Depth() int

Depth returns node depth in index matrix.

func (*Node) Dot

func (n *Node) Dot(path string) *Node

Dot looks and get child node by given path and "." separator.

func (*Node) DotArray

func (n *Node) DotArray(path string) *Node

DotArray looks and get child array by given path and "." separator.

func (*Node) DotBool

func (n *Node) DotBool(path string) bool

DotBool looks and get child bool by given path and "." separator.

func (*Node) DotBytes

func (n *Node) DotBytes(path string) []byte

DotBytes looks and get child bytes by given path and "." separator.

func (*Node) DotFloat

func (n *Node) DotFloat(path string) (float64, error)

DotFloat looks and get child float by given path and "." separator.

func (*Node) DotInt

func (n *Node) DotInt(path string) (int64, error)

DotInt looks and get child integer by given path and "." separator.

func (*Node) DotObject

func (n *Node) DotObject(path string) *Node

DotObject looks and get child object by given path and "." separator.

func (*Node) DotString

func (n *Node) DotString(path string) string

DotString looks and get child string by given path and "." separator.

func (*Node) DotUint

func (n *Node) DotUint(path string) (uint64, error)

DotUint looks and get child unsigned int by given path and "." separator.

func (*Node) Each

func (n *Node) Each(fn func(idx int, node *Node))

Each applies custom function to each child of the node.

func (*Node) EqualWith added in v1.2.3

func (n *Node) EqualWith(exp *Node) bool

EqualWith compares node with exp.

func (*Node) Exists

func (n *Node) Exists(key string) bool

Exists checks if given key exists in the node.

func (*Node) Float

func (n *Node) Float() (float64, error)

Float returns value as float number.

func (*Node) ForceBytes

func (n *Node) ForceBytes() []byte

ForceBytes returns value as bytes independent of the type.

func (*Node) ForceString

func (n *Node) ForceString() string

ForceString returns value as string independent of the type.

func (*Node) Get

func (n *Node) Get(keys ...string) *Node

Get returns child node by given keys.

func (*Node) GetArray

func (n *Node) GetArray(keys ...string) *Node

GetArray looks and get child array by given keys.

func (*Node) GetArrayPS

func (n *Node) GetArrayPS(path, separator string) *Node

GetArrayPS looks and get child array by given path and separator.

func (*Node) GetBool

func (n *Node) GetBool(keys ...string) bool

GetBool looks and get child bool by given keys.

func (*Node) GetBoolPS

func (n *Node) GetBoolPS(path, separator string) bool

GetBoolPS looks and get child bool by given path and separator.

func (*Node) GetBytes

func (n *Node) GetBytes(keys ...string) []byte

GetBytes looks and get child bytes by given keys.

func (*Node) GetBytesPS

func (n *Node) GetBytesPS(path, separator string) []byte

GetBytesPS looks and get child bytes by given path and separator.

func (*Node) GetFloat

func (n *Node) GetFloat(keys ...string) (float64, error)

GetFloat looks and get child float by given keys.

func (*Node) GetFloatPS

func (n *Node) GetFloatPS(path, separator string) (float64, error)

GetFloatPS looks and get child float by given path and separator.

func (*Node) GetInt

func (n *Node) GetInt(keys ...string) (int64, error)

GetInt looks and get child integer by given keys.

func (*Node) GetIntPS

func (n *Node) GetIntPS(path, separator string) (int64, error)

GetIntPS looks and get child integer by given path and separator.

func (*Node) GetObject

func (n *Node) GetObject(keys ...string) *Node

GetObject looks and get child object by given keys.

func (*Node) GetObjectPS

func (n *Node) GetObjectPS(path, separator string) *Node

GetObjectPS looks and get child object by given path and separator.

func (*Node) GetPS

func (n *Node) GetPS(path, separator string) *Node

GetPS returns child node by path and separator.

func (*Node) GetString

func (n *Node) GetString(keys ...string) string

GetString looks and get child string by given keys.

func (*Node) GetStringPS

func (n *Node) GetStringPS(path, separator string) string

GetStringPS looks and get child string by given path and separator.

func (*Node) GetUint

func (n *Node) GetUint(keys ...string) (uint64, error)

GetUint looks and get child unsigned integer by given keys.

func (*Node) GetUintPS

func (n *Node) GetUintPS(path, separator string) (uint64, error)

GetUintPS looks and get child unsigned int by given path and separator.

func (*Node) Index

func (n *Node) Index() int

Index returns node index in the array of nodes.

func (*Node) Int

func (n *Node) Int() (int64, error)

Int returns value as integer.

func (*Node) Key

func (n *Node) Key() *Byteptr

Key returns key as byteptr object.

func (*Node) KeyBytes

func (n *Node) KeyBytes() []byte

KeyBytes returns key as bytes.

func (*Node) KeyString

func (n *Node) KeyString() string

KeyString returns key as string.

func (*Node) Limit

func (n *Node) Limit() int

Limit returns limit of childs in index row.

func (*Node) Look

func (n *Node) Look(key string) *Node

Look for the child node by given key.

May be used only for object nodes.

func (*Node) Marshal added in v1.2.4

func (n *Node) Marshal(w io.Writer) error

Marshal serializes node.

func (*Node) Object

func (n *Node) Object() *Node

Object checks node is object and return it.

func (*Node) Offset

func (n *Node) Offset() int

Offset returns offset of childs in the index row.

func (*Node) RawBytes

func (n *Node) RawBytes() []byte

RawBytes returns value as bytes without implement any conversion logic.

func (*Node) RemoveIf added in v1.2.3

func (n *Node) RemoveIf(cond func(idx int, node *Node) bool)

RemoveIf deletes all children nodes satisfies condition cond.

func (*Node) Reset

func (n *Node) Reset() *Node

Reset the node.

func (*Node) SetLimit

func (n *Node) SetLimit(limit int) *Node

SetLimit sets limit of childs in index row.

func (*Node) SetOffset

func (n *Node) SetOffset(offset int) *Node

SetOffset sets offset in the index row.

func (*Node) SetType

func (n *Node) SetType(typ Type)

SetType sets type of the node.

func (*Node) Sort

func (n *Node) Sort() *Node

Sort sorts child nodes by value in AB order.

func (*Node) SortKeys

func (n *Node) SortKeys() *Node

SortKeys sorts child nodes by key in AB order.

func (*Node) String

func (n *Node) String() string

Get value as string.

Allow only for [string, number, bool, attribute] types.

func (*Node) SwapWith

func (n *Node) SwapWith(node *Node)

SwapWith swaps node with another given node in the nodes array.

func (*Node) Type

func (n *Node) Type() Type

Type returns node type.

func (*Node) Uint

func (n *Node) Uint() (uint64, error)

Uint returns value as unsigned integer.

func (*Node) Value

func (n *Node) Value() *Byteptr

Value returns value as byteptr object.

type Type

type Type int

Type represents Node type.

const (
	TypeUnk Type = iota
	TypeNull
	TypeObj
	TypeArr
	TypeStr
	TypeNum
	TypeBool
	TypeAttr
)

type Vector

type Vector struct {
	bitset.Bitset

	// Nodes index.
	Index Index
	// External helper object.
	Helper Helper
	// contains filtered or unexported fields
}

Vector parser object.

func (*Vector) Beautify

func (vec *Vector) Beautify(w io.Writer) error

Beautify formats first root node in human-readable representation.

Second and next roots must beautify manually by call Beautify method of each node.

func (*Vector) Buf

func (vec *Vector) Buf() []byte

Buf returns raw buffer bytes.

func (*Vector) BufAppend

func (vec *Vector) BufAppend(s []byte)

BufAppend appends bytes to the buffer.

func (*Vector) BufAppendByte

func (vec *Vector) BufAppendByte(b byte)

BufAppendByte appends single byte to the buffer.

func (*Vector) BufAppendFloat

func (vec *Vector) BufAppendFloat(f float64)

BufAppendFloat appends float to the buffer.

func (*Vector) BufAppendFloatTune

func (vec *Vector) BufAppendFloatTune(f float64, fmt byte, prec, bitSize int)

BufAppendFloatTune appends float with extended params to the buffer.

func (*Vector) BufAppendInt

func (vec *Vector) BufAppendInt(i int64)

BufAppendInt appends int to the buffer.

func (*Vector) BufAppendStr

func (vec *Vector) BufAppendStr(s string)

BufAppendStr appends string to the buffer.

func (*Vector) BufAppendUint

func (vec *Vector) BufAppendUint(u uint64)

BufAppendUint appends uint to the buffer.

func (*Vector) BufLen

func (vec *Vector) BufLen() int

BufLen returns length of buffer.

func (*Vector) BufUpdateWith

func (vec *Vector) BufUpdateWith(b []byte)

BufUpdateWith replaces buffer with b.

func (*Vector) Dot

func (vec *Vector) Dot(path string) *Node

Dot looks and get node by given path and "." separator.

func (*Vector) DotArray

func (vec *Vector) DotArray(path string) *Node

DotArray looks and get array by given path and "." separator.

func (*Vector) DotBool

func (vec *Vector) DotBool(path string) bool

DotBool looks and get bool by given path and "." separator.

func (*Vector) DotBytes

func (vec *Vector) DotBytes(path string) []byte

DotBytes looks and get bytes by given path and "." separator.

func (*Vector) DotFloat

func (vec *Vector) DotFloat(path string) (float64, error)

DotFloat looks and get float by given path and "." separator.

func (*Vector) DotInt

func (vec *Vector) DotInt(path string) (int64, error)

DotInt looks and get integer by given path and "." separator.

func (*Vector) DotObject

func (vec *Vector) DotObject(path string) *Node

DotObject looks and get object by given path and "." separator.

func (*Vector) DotString

func (vec *Vector) DotString(path string) string

DotString looks and get string by given path and "." separator.

func (*Vector) DotUint

func (vec *Vector) DotUint(path string) (uint64, error)

DotUint looks and get unsigned integer by given path and "." separator.

func (*Vector) Each

func (vec *Vector) Each(fn func(idx int, node *Node))

Each applies custom function to each root node.

func (*Vector) EqualWith added in v1.2.3

func (vec *Vector) EqualWith(exp *Vector) bool

EqualWith compares vector with exp.

func (*Vector) ErrorOffset

func (vec *Vector) ErrorOffset() int

ErrorOffset returns last error offset.

func (*Vector) Exists

func (vec *Vector) Exists(key string) bool

Exists checks if node exists by given key.

func (*Vector) ForgetFrom

func (vec *Vector) ForgetFrom(idx int)

ForgetFrom forgets nodes from given position to the end of the array.

func (*Vector) Get

func (vec *Vector) Get(keys ...string) *Node

Get returns node by given keys.

func (*Vector) GetArray

func (vec *Vector) GetArray(keys ...string) *Node

GetArray looks and get array by given keys.

func (*Vector) GetArrayPS

func (vec *Vector) GetArrayPS(path, separator string) *Node

GetArrayPS looks and get array by given path and separator.

func (*Vector) GetBool

func (vec *Vector) GetBool(keys ...string) bool

GetBool looks and get bool by given keys.

func (*Vector) GetBoolPS

func (vec *Vector) GetBoolPS(path, separator string) bool

GetBoolPS looks and get bool by given path and separator.

func (*Vector) GetByIdx

func (vec *Vector) GetByIdx(idx int) *Node

GetByIdx returns node by known index in nodes array.

func (*Vector) GetBytes

func (vec *Vector) GetBytes(keys ...string) []byte

GetBytes looks and get bytes by given keys.

func (*Vector) GetBytesPS

func (vec *Vector) GetBytesPS(path, separator string) []byte

GetBytesPS looks and get bytes by given path and separator.

func (*Vector) GetChild

func (vec *Vector) GetChild(root *Node, depth int) (*Node, int)

GetChild get node and register it as a child of root node.

Similar to GetNode.

func (*Vector) GetChildWT

func (vec *Vector) GetChildWT(root *Node, depth int, typ Type) (*Node, int)

GetChildWT get node, register it as a child of root node and set type at once.

func (*Vector) GetFloat

func (vec *Vector) GetFloat(keys ...string) (float64, error)

GetFloat looks and get float by given keys.

func (*Vector) GetFloatPS

func (vec *Vector) GetFloatPS(path, separator string) (float64, error)

GetFloatPS looks and get float by given path and separator.

func (*Vector) GetInt

func (vec *Vector) GetInt(keys ...string) (int64, error)

GetInt looks and get integer by given keys.

func (*Vector) GetIntPS

func (vec *Vector) GetIntPS(path, separator string) (int64, error)

GetIntPS looks and get integer by given path and separator.

func (*Vector) GetNode

func (vec *Vector) GetNode(depth int) (node *Node, idx int)

GetNode returns new node with index from position matrix by given depth.

func (*Vector) GetNodeWT

func (vec *Vector) GetNodeWT(depth int, typ Type) (*Node, int)

GetNodeWT returns node and set type at once.

func (*Vector) GetObject

func (vec *Vector) GetObject(keys ...string) *Node

GetObject looks and get object by given keys.

func (*Vector) GetObjectPS

func (vec *Vector) GetObjectPS(path, separator string) *Node

GetObjectPS looks and get object by given path and separator.

func (*Vector) GetPS

func (vec *Vector) GetPS(path, separator string) *Node

GetPS returns node by given path and separator.

func (*Vector) GetString

func (vec *Vector) GetString(keys ...string) string

GetString looks and get string by given keys.

func (*Vector) GetStringPS

func (vec *Vector) GetStringPS(path, separator string) string

GetStringPS looks and get string by given path and separator.

func (*Vector) GetUint

func (vec *Vector) GetUint(keys ...string) (uint64, error)

GetUint looks and get unsigned integer by given keys.

func (*Vector) GetUintPS

func (vec *Vector) GetUintPS(path, separator string) (uint64, error)

GetUintPS looks and get unsigned integer by given path and separator.

func (*Vector) KeepPtr

func (vec *Vector) KeepPtr()

KeepPtr guarantees that vector object wouldn't be collected by GC.

Typically, vector objects uses together with pools and GC doesn't collect them. But for cases like vec := &Vector{...} node := vec.Get("foo", "bar") <- here GC may collect vec fmt.Println(node.String()) <- invalid operation due to vec already has been collected vec.KeepPtr() <- just call me to avoid that trouble

func (*Vector) Len

func (vec *Vector) Len() int

Len returns length of nodes array.

func (*Vector) Marshal added in v1.2.4

func (vec *Vector) Marshal(w io.Writer) error

Marshal serializes first root node.

Second and next roots must beautify manually by call Marshal method of each node.

func (*Vector) NodeAt

func (vec *Vector) NodeAt(idx int) *Node

NodeAt returns node at given position.

func (*Vector) Parse

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

Parse parses source bytes.

func (*Vector) ParseCopy

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

ParseCopy copies source bytes and parse it.

func (*Vector) ParseCopyStr

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

ParseCopyStr copies source string and parse it.

func (*Vector) ParseStr

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

ParseStr parses source string.

func (*Vector) Prealloc added in v1.2.5

func (vec *Vector) Prealloc(size uint)

Prealloc prepares space for further parse.

func (*Vector) PutNode

func (vec *Vector) PutNode(idx int, node *Node)

PutNode returns node back to the array.

func (*Vector) RemoveIf added in v1.2.3

func (vec *Vector) RemoveIf(cond func(idx int, node *Node) bool)

RemoveIf deletes all root nodes satisfies condition cond.

func (*Vector) Reset

func (vec *Vector) Reset()

Reset vector data.

func (*Vector) Root

func (vec *Vector) Root() *Node

Root returns root node.

func (*Vector) RootByIndex

func (vec *Vector) RootByIndex(index int) *Node

RootByIndex returns root node by given index.

For cases when one vector instance uses for parse many sources.

func (*Vector) RootLen

func (vec *Vector) RootLen() int

RootLen returns count of root nodes.

func (*Vector) RootTop

func (vec *Vector) RootTop() *Node

RootTop returns last root node.

func (*Vector) SetErrOffset

func (vec *Vector) SetErrOffset(offset int)

SetErrOffset sets error offset.

func (*Vector) SetHelper

func (vec *Vector) SetHelper(helper Helper)

SetHelper sets helper to vector object.

func (*Vector) SetSrc

func (vec *Vector) SetSrc(s []byte, copy bool) error

SetSrc sets source bytes.

func (*Vector) Src

func (vec *Vector) Src() []byte

Src returns raw source bytes.

Please note, source bytes may be "corrupt" when unescaped.

func (*Vector) SrcAddr

func (vec *Vector) SrcAddr() uintptr

SrcAddr returns source address in virtual memory.

func (*Vector) SrcAt

func (vec *Vector) SrcAt(i int) byte

SrcAt returns byte at position i.

func (*Vector) SrcLen

func (vec *Vector) SrcLen() int

SrcLen returns length of source bytes.

Jump to

Keyboard shortcuts

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