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
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