utils

package
v0.0.0-...-7923ec7 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerLevel zap.AtomicLevel

Functions

func BadDeveloperError

func BadDeveloperError(msg string)

BadDeveloperError panics with a message that indicates a bug in the code. It should only be used in places that should never be reached or can only be reached if there is a bug in the code.

func CreateCacheBucket

func CreateCacheBucket(bucket string)

CreateCacheBucket creates a cache bucket

func EvictCache

func EvictCache(bucket, key string)

EvictCache evicts a cache entry

func GetCache

func GetCache(bucket, key string) *interface{}

GetCache gets a cache entry

func InitLogging

func InitLogging(level zapcore.Level)

func PutCache

func PutCache(bucket, key string, value interface{})

PutCache puts a cache entry

func WalkDirFollowSymlinks(root string, fn fs.WalkDirFunc) error

WalkDirFollowSymlinks walks the directory tree rooted at root, calling fn for each file or directory. If a directory is a symlink, its contents are also walked.

func WrapJsonErrorf

func WrapJsonErrorf(path string, err error, text string, args ...interface{}) error

WrapJsonErrorf wraps an error with a stack trace and adds additional formatted text information.

func WrapRange

func WrapRange(value, start, end int) int

func WrappedJsonErrorf

func WrappedJsonErrorf(path string, text string, args ...interface{}) error

WrappedJsonErrorf creates an error with a stack trace from formatted text and appends the path.

Types

type CacheBucket

type CacheBucket struct {
	Items map[string]*interface{}
	// contains filtered or unexported fields
}

CacheBucket is a bucket of cache entries

type Index

type Index struct {
	Src       []byte
	Nodes     []Node
	ChildRefs []int32
	// contains filtered or unexported fields
}

Index is a structural representation of a JSON document without materializing values.

func Build

func Build(src []byte) (*Index, error)

Build parses JSON/JSONC bytes into an Index.

func (*Index) BuildKeyTable

func (idx *Index) BuildKeyTable(objIdx int, buf []KeyTableEntry) ([]KeyTableEntry, error)

BuildKeyTable returns object members sorted by (hash, canonical-key-bytes). If buf is nil, it may return an internal cached slice.

func (*Index) Children

func (idx *Index) Children(n int) []int

Children returns direct child node indices for node n. It returns nil for leaves and out-of-range indices.

type KeyTableEntry

type KeyTableEntry struct {
	Hash uint64

	// Raw key span (without quotes, escapes still present in source bytes).
	KeyLo int32
	KeyHi int32

	ValIndex  int32
	HasDollar bool
	HasCaret  bool
	HasEscape bool
}

KeyTableEntry stores preprocessed object member metadata. Hash is computed from the unescaped key bytes.

type Kind

type Kind uint8

Kind describes the JSON node type.

const (
	Object Kind = iota
	Array
	String
	Number
	Boolean
	Null
)
type NavigableMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func MapToNavigableMap

func MapToNavigableMap(entries map[string]interface{}) NavigableMap[string, interface{}]

MapToNavigableMap creates a new NavigableMap from a golang map.

func NewNavigableMap

func NewNavigableMap[K comparable, V any]() NavigableMap[K, V]

NewNavigableMap creates a new NavigableMap.

func NewNavigableMapWithCapacity

func NewNavigableMapWithCapacity[K comparable, V any](capacity int) NavigableMap[K, V]

NewNavigableMapWithCapacity creates a new NavigableMap with preallocated storage.

func ToNavigableMap

func ToNavigableMap(entries ...interface{}) NavigableMap[string, interface{}]

ToNavigableMap creates a new NavigableMap with given keys and values.

func (m *NavigableMap[K, V]) AppendKeys(dst []K) []K
func (m *NavigableMap[K, V]) AppendValues(dst []V) []V
func (m *NavigableMap[K, V]) Clear()
func (m *NavigableMap[K, V]) Compact()
func (m *NavigableMap[K, V]) ContainsKey(key K) bool
func (m *NavigableMap[K, V]) ContainsMatchingKey(match func(K) bool) bool

ContainsMatchingKey returns true if match(key) is true for any key. It uses Range (slice-based, no hashing) and short-circuits on first hit.

func (m *NavigableMap[K, V]) ForEach(fn func(K, V))

For compatibility with existing code:

func (m *NavigableMap[K, V]) ForEachUntil(fn func(K, V) bool)
func (m *NavigableMap[K, V]) Get(key K) V
func (m *NavigableMap[K, V]) IsEmpty() bool
func (m *NavigableMap[K, V]) Keys() []K
func (m *NavigableMap[K, V]) Put(key K, value V)
func (m *NavigableMap[K, V]) Range(fn func(K, V) bool)
func (m *NavigableMap[K, V]) Remove(key K)
func (m *NavigableMap[K, V]) Reserve(n int)

Reserve grows internal capacity to at least n additional free slots.

func (m *NavigableMap[K, V]) SetAutoCompact(percent, minTombstones int)

SetAutoCompact sets the automatic compaction thresholds. percent is the minimum percentage of tombstones (0..100) to trigger compaction. minTombstones is the minimum absolute number of tombstones to trigger compaction. SetAutoCompact(0, 0) disables automatic compaction.

func (m *NavigableMap[K, V]) Size() int
func (m *NavigableMap[K, V]) Sort(comparer func(K, K) int)

Sort orders valid entries by the provided comparer while keeping stability. It avoids touching tombstones during compare/swap by sorting a dense index list, then applies the permutation once to keys/values/valid and rebuilds index.

func (m *NavigableMap[K, V]) TryGet(key K) (V, bool)
func (m *NavigableMap[K, V]) Values() []V

type Node

type Node struct {
	Kind   Kind
	Parent int32

	// Direct children live in Index.ChildRefs[ChildLo:ChildHi].
	ChildLo int32
	ChildHi int32

	// ValLo/ValHi points to the exact value bytes in source.
	ValLo int32
	ValHi int32

	// Key span without surrounding quotes.
	KeyLo int32
	KeyHi int32
}

Node points into the original source bytes. KeyLo/KeyHi are set only for object members; for array elements they are -1.

Jump to

Keyboard shortcuts

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