stringbank

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2019 License: MIT Imports: 2 Imported by: 2

README

stringbank

GoDoc Build Status

stringbank allows you to hold large numbers of strings without bothering the garbage collector. For small strings storage is reduced as the lengths are encoded compactly.

Documentation

Overview

Package stringbank allows you to hold large numbers of strings without bothering the garbage collector. For small strings storage is reduced as the lengths are encoded compactly.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

type Index int

Index is returned by Save and can be converted into the saved string by calling it's String() method

func Save

func Save(val string) Index

Save stores the string in the default package-level Stringbank, and returns an Index which can be converted back to the original string by calling its String() method

Example
i := Save("hello")
fmt.Println(i)
Output:

hello

func (Index) String

func (i Index) String() string

type Stringbank

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

Stringbank is a place to put strings that never need to be deleted. Saving a string into the Stringbank returns an integer offset for the string, so the string can be stored and referenced without bothering the garbage collector. The offset can be exchanged for the original string via a call to Get

Example
sb := Stringbank{}
i := sb.Save("goodbye")
fmt.Println(sb.Get(i))
Output:

goodbye

func (*Stringbank) Get

func (s *Stringbank) Get(index int) string

Get converts an index to the original string

func (*Stringbank) Save

func (s *Stringbank) Save(tocopy string) int

Save copies a string into the Stringbank, and returns the index of the string in the bank

func (*Stringbank) Size

func (s *Stringbank) Size() int

Size returns the approximate number of bytes in the string bank. The estimate includes currently 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