idx

package
v0.0.0-...-cf3773c Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package idx implements reading .idx files.

The .idx file contains a list of dictionary entry titles and the associated offset and size of the main article content in the .dict file.

Each .idx file entry (word) comes in three parts:

  1. The title: a utf-8 string terminated by a null terminator ('\0').
  2. The offset: a 32 or 64 bit integer offset of the word in the .dict file in network byte order.
  3. The size: a 32 bit integer size of the word in the .dict file in network byte order.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeIndex

func MakeIndex(words []*Word, idxoffsetbits int64) []byte

MakeIndex make a test index given a list of words.

Types

type Idx

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

Idx is a very basic implementation of an in memory search index. Implementers of dictionaries apps or tools may wish to consider using Scanner to read the .idx file and generate their own more robust search index.

func New

func New(r io.ReadCloser, idxoffsetbits int64) (*Idx, error)

New returns a new in-memory index.

func (*Idx) FullTextSearch

func (idx *Idx) FullTextSearch(str string) []*Word

FullTextSearch searches full text of index entries.

type Scanner

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

Scanner scans an index from start to end.

func NewScanner

func NewScanner(r io.ReadCloser, idxoffsetbits int64) (*Scanner, error)

NewScanner return a new index scanner that scans the index from start to end.

func (*Scanner) Close

func (s *Scanner) Close() error

Close closes the underlying reader.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first error encountered.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan advances the index to the next index entry. It returns false if the scan stops either by reaching the end of the index or an error.

func (*Scanner) Word

func (s *Scanner) Word() *Word

Word gets the next entry in the index.

type Word

type Word struct {
	Word   string
	Offset uint64
	Size   uint32
}

Word is an .idx file entry.

Jump to

Keyboard shortcuts

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