Documentation
¶
Index ¶
Constants ¶
const ( // NoRecord is the special index returned for non-member enums. Notice that the member // indexes always start from 1, hence 0 is never used. NoRecord uint = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
Enum is the enumeration object, which holds one or more string values. Each string value is assigned a unique uint index and allows for quick lookup. An Enum is read-only after creation.
func New ¶
New creates an Enum with the given values. The items in the Enum will be indexed sequentially in the order of values, starting at 1. For instance:
// one is indexed at 1 // two is indexed at 2 // three is indexed at 3 New("one", "two", "three")
This constructor fits the most use cases where a value is assigned a single enumeration. For instance:
var someType = New("one", "two", "three") var some = "one" // or "two", or "three" var indexOfOne = someType.Index(some) var _some = someType.Value(indexOfOne)
This constructor does NOT cover cases where a value may correspond to several values of enumerations, such as in a "Set" data structure. See NewComposite for this case.
func NewComposite ¶
NewComposite creates an Enum with the given values. The items in the Enum will be indexed sequentially in the order of 2. For instance:
// one is indexed at 1 // two is indexed at 2 // three is indexed at 4 NewComposite("one", "two", "three")
This constructor fits the most use cases where a value is assigned one or more enumeration. For instance:
var someType = NewComposite("one", "two", "three") var some = []string{"one", "three"} var bitmap = someType.BitMap(some...) // bitmap == 5 var values = someType.Hydrate(bitmap) // values == ["one", "three"]
func NewCustom ¶
NewCustom creates an Enum with the given values and the indexFunc will be used to index each value at position i.
func (*Enum) BitMap ¶
BitMap returns a bit map of given values in the Enum. Caution that only Enum created with NewComposite should use this method, as other Enum could have applied overlapping indexed which result in a irreversible bitmap.
func (*Enum) Hydrate ¶
Hydrate reverses the computed bitmap and returns the corresponding values. Caution that only Enum created with NewComposite should use this method.
func (*Enum) Index ¶
Index returns the index of the given value. If the value does not exist in the Enum, a special NoRecord index is returned.