enumcache

package
v1.101.19 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package enumcache provides a collection of thread-safe methods for storing and retrieving enumeration sets with integer IDs and string names. It includes support for binary maps (github.com/Vonage/gosrvlib/pkg/enumbitmap), where each bit represents a different name in the enumeration set.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnumCache

type EnumCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EnumCache handles name and id value mapping.

func New

func New() *EnumCache

New returns a new empty EnumCache.

Example
Output:

1
alpha

func (*EnumCache) DecodeBinaryMap

func (ec *EnumCache) DecodeBinaryMap(v int) ([]string, error)

DecodeBinaryMap decodes a int binary map into a list of string names. The EnumCache must contain the mapping between the bit values and the names.

Example
Output:

[third fifth seventh]

func (*EnumCache) EncodeBinaryMap

func (ec *EnumCache) EncodeBinaryMap(s []string) (int, error)

EncodeBinaryMap encode a list of string names into a int binary map. The EnumCache must contain the mapping between the bit values and the names.

Example
Output:

42

func (*EnumCache) ID

func (ec *EnumCache) ID(name string) (int, error)

ID returns the numerical ID associated to the given name.

func (*EnumCache) Name

func (ec *EnumCache) Name(id int) (string, error)

Name returns the name associated with the given numerical ID.

func (*EnumCache) Set

func (ec *EnumCache) Set(id int, name string)

Set a single id-name key-value.

func (*EnumCache) SetAllIDByName

func (ec *EnumCache) SetAllIDByName(enum IDByName)

SetAllIDByName sets all the specified enumeration ID values indexed by Name.

Example
Output:

23
second

func (*EnumCache) SetAllNameByID

func (ec *EnumCache) SetAllNameByID(enum NameByID)

SetAllNameByID sets all the specified enumeration Name values indexed by ID.

Example
Output:

23
second

func (*EnumCache) SortIDs

func (ec *EnumCache) SortIDs() []int

SortIDs returns a list of sorted IDs.

Example
Output:

[11 22 33 44 55 66]

func (*EnumCache) SortNames

func (ec *EnumCache) SortNames() []string

SortNames returns a list of sorted names.

Example
Output:

[alpha bravo charlie delta echo foxtrot]

type IDByName

type IDByName map[string]int

IDByName type maps strings to integers IDs.

type NameByID

type NameByID map[int]string

NameByID maps integers to string names.

Jump to

Keyboard shortcuts

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