numtree

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package numtree implements PDF number trees.

Number trees serve a similar purpose to dictionaries, associating keys and values, but using integer keys instead of name objects. The keys are stored in sorted numerical order, and the data structure can represent an arbitrarily large collection of key-value pairs with efficient lookup without requiring the entire structure to be read from the PDF file.

This package provides two implementations:

  • InMemory: loads the entire tree into memory for fast access
  • FromFile: reads nodes on demand for memory-efficient access to large trees

The Write function creates balanced number trees using a streaming B-tree algorithm that processes entries incrementally with O(log n) memory usage.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

Functions

func Size added in v0.7.0

func Size(r pdf.Getter, root pdf.Object) (int, error)

Size returns the number of entries in the number tree, without reading the entire tree into memory.

func Write

func Write(w *pdf.Writer, data iter.Seq2[pdf.Integer, pdf.Object]) (pdf.Reference, error)

Write creates a number tree in the PDF file. The iterator `data` provides the key-value pairs. The keys must be returned in sorted order, and must not contain duplicates. The return value is the reference to the number tree root.

Types

type FromFile added in v0.7.0

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

FromFile represents a number tree that allows reading values from a PDF file without holding the entire tree in memory.

func ExtractFromFile added in v0.7.0

func ExtractFromFile(r pdf.Getter, root pdf.Object) (*FromFile, error)

ExtractFromFile creates a new FromFile number tree that reads from a PDF document. If root is nil, it returns nil.

func (*FromFile) All added in v0.7.0

func (t *FromFile) All() iter.Seq2[pdf.Integer, pdf.Object]

func (*FromFile) Embed added in v0.7.0

func (t *FromFile) Embed(rm *pdf.EmbedHelper) (pdf.Native, error)

func (*FromFile) Lookup added in v0.7.0

func (t *FromFile) Lookup(key pdf.Integer) (pdf.Object, error)

type InMemory added in v0.7.0

type InMemory struct {
	Data map[pdf.Integer]pdf.Object
}

InMemory represents a number tree held entirely in memory.

func ExtractInMemory added in v0.7.0

func ExtractInMemory(r pdf.Getter, root pdf.Object) (*InMemory, error)

ExtractInMemory reads a number tree from a PDF document into memory. If obj is nil, it returns nil.

func (*InMemory) All added in v0.7.0

func (t *InMemory) All() iter.Seq2[pdf.Integer, pdf.Object]

func (*InMemory) Embed added in v0.7.0

func (t *InMemory) Embed(rm *pdf.EmbedHelper) (pdf.Native, error)

Embed adds the number tree to a PDF file.

func (*InMemory) Lookup added in v0.7.0

func (t *InMemory) Lookup(key pdf.Integer) (pdf.Object, error)

Jump to

Keyboard shortcuts

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