symboltab

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 4 Imported by: 1

README

GoDoc Build Status

I've called this a "symbol table". It converts a string ID to an integer sequence number. The integers start at 1 and increase by 1 for each new unique string. The intention is to store a very large number of strings, so the library is light on GC.

The idea behind the symbol table is to convert string IDs into integer IDs that can then be used for fast comparison and array/slice lookups

Documentation

Overview

Package symboltab is a symbol table. It converts strings to sequence numbers. This is useful for things like graph algorithms, where IDs are stored and compared a lot.

symboltab is optimised for storing a lot of strings, so things are optimised for reducing work for the GC

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Naive added in v1.1.2

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

Naive implementation of the same function. Really just intended to compare against

func NewNaive added in v1.1.2

func NewNaive(cap int) *Naive

NewNaive creates a new, basic implementation of the symboltable function

func (*Naive) SequenceToString added in v1.1.2

func (n *Naive) SequenceToString(seq int32) string

SequenceToString retrieves the string for a sequence number

func (*Naive) StringToSequence added in v1.1.2

func (n *Naive) StringToSequence(val string, addNew bool) (seq int32, found bool)

StringToSequence converts a string to a sequence number

type SymbolTab

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

SymbolTab is the symbol table. Allocate it via New()

Example
st := SymbolTab{}
seq, found := st.StringToSequence("10293-ahdb-28383-555", true)
fmt.Println(found)
fmt.Println(st.SequenceToString(seq))
Output:

false
10293-ahdb-28383-555

func New

func New(cap int) *SymbolTab

New creates a new SymbolTab. cap is the initial capacity of the table - it will grow automatically when needed

func (*SymbolTab) Cap

func (i *SymbolTab) Cap() int

Cap returns the size of the SymbolTab table

func (*SymbolTab) Len

func (i *SymbolTab) Len() int

Len returns the number of unique strings stored

func (*SymbolTab) SequenceToString

func (i *SymbolTab) SequenceToString(seq int32) string

SequenceToString looks up a string by its sequence number. Obtain the sequence number for a string with StringToSequence

func (*SymbolTab) StringToSequence

func (i *SymbolTab) StringToSequence(val string, addNew bool) (seq int32, found bool)

StringToSequence looks up the string val and returns its sequence number seq. If val does not currently exist in the symbol table, it will add it if addNew is true. found indicates whether val was already present in the SymbolTab

func (*SymbolTab) SymbolSize

func (i *SymbolTab) SymbolSize() int

SymbolSize contains the approximate size of string storage in the symboltable. This will be an over-estimate and includes as yet unused and wasted space

Directories

Path Synopsis
offheap module

Jump to

Keyboard shortcuts

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