Documentation ¶
Index ¶
- type Set
- func (s Set[V]) AsArray() (a []V)
- func (s Set[V]) AsBytes() []byte
- func (s *Set[V]) Clear(values ...V)
- func (s *Set[V]) ClearAll()
- func (s Set[V]) Clone() Set[V]
- func (s Set[V]) Contains(v V) bool
- func (s Set[V]) ContainsAll(values ...V) bool
- func (s Set[V]) ContainsAny(values ...V) bool
- func (s Set[V]) Enumerate(visit func(V))
- func (s Set[V]) First() (V, bool)
- func (s Set[V]) Len() int
- func (s *Set[V]) Set(values ...V)
- func (s *Set[V]) SetRange(start, end V)
- func (s Set[V]) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[V ~uint8] struct { // contains filtered or unexported fields }
Set represents a set of values of type V.
V must be uint8.
func Empty ¶
Makes new empty Set of specified value type. Same as `Set[V]{}`.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new empty Set. s := set.Empty[Month]() fmt.Println(s) }
Output: []
func From ¶
Makes new Set from specified values.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) fmt.Println(s.AsArray()) }
Output: [Month_jan Month_feb Month_mar]
func (Set[V]) AsArray ¶
func (s Set[V]) AsArray() (a []V)
Represents Set as array.
If Set is empty, returns nil.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Receive values from Set as array. fmt.Println(s.AsArray()) }
Output: [Month_jan Month_feb Month_mar]
func (Set[V]) AsBytes ¶
Returns Set bitmap as big-endian bytes.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Receive Set as big-endian bytes. fmt.Printf("%b", s.AsBytes()) }
Output: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 111]
func (*Set[V]) Clear ¶
func (s *Set[V]) Clear(values ...V)
Clears specified elements from set.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Clear specified values from Set. s.Clear(Month_jan) fmt.Println(s) }
Output: [feb mar]
func (*Set[V]) ClearAll ¶
func (s *Set[V]) ClearAll()
Clears all elements from Set.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Clear all values from Set. s.ClearAll() fmt.Println(s) }
Output: []
func (Set[V]) Contains ¶
Returns is Set contains specified value.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Check if Set contains specified value. fmt.Println(s.Contains(Month_jan)) fmt.Println(s.Contains(Month_nov)) }
Output: true false
func (Set[V]) ContainsAll ¶
Returns is Set contains all from specified values.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Check if Set contains all specified values. fmt.Println(s.ContainsAll(Month_jan, Month_mar)) fmt.Println(s.ContainsAll(Month_jan, Month_nov)) }
Output: true false
func (Set[V]) ContainsAny ¶
Returns is Set contains at least one from specified values. If values is empty, returns true.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Check if Set contains at least one of specified values. fmt.Println(s.ContainsAny(Month_jan, Month_mar)) fmt.Println(s.ContainsAny(Month_nov, Month_dec)) }
Output: true false
func (Set[V]) Enumerate ¶
func (s Set[V]) Enumerate(visit func(V))
Enumerate calls visit for each value in Set.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Enumerate values from Set. s.Enumerate(func(v Month) { fmt.Println(v) }) }
Output: Month_jan Month_feb Month_mar
func (Set[V]) First ¶
Returns is Set filled and first value set. If Set is empty, returns false and zero value.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Get first value from Set. fmt.Println(s.First()) }
Output: Month_jan true
func (Set[V]) Len ¶
Returns count of values in Set.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Get count of values in Set. fmt.Println(s.Len()) }
Output: 3
func (*Set[V]) SetRange ¶
func (s *Set[V]) SetRange(start, end V)
Sets range of value to Set. Inclusive start, exclusive end.
Example ¶
package main import ( "fmt" "strings" "github.com/voedger/voedger/pkg/goutils/set" ) type Month uint8 const ( Month_jan Month = iota Month_feb Month_mar Month_apr Month_may Month_jun Month_jul Month_aug Month_sep Month_oct Month_nov Month_dec Month_count ) var TypeKindStr = map[Month]string{ Month_jan: "Month_jan", Month_feb: "Month_feb", Month_mar: "Month_mar", Month_apr: "Month_apr", Month_may: "Month_may", Month_jun: "Month_jun", Month_jul: "Month_jul", Month_aug: "Month_aug", Month_sep: "Month_sep", Month_oct: "Month_oct", Month_nov: "Month_nov", Month_dec: "Month_dec", } func (t Month) String() string { if s, ok := TypeKindStr[t]; ok { return s } return fmt.Sprintf("Month(%d)", t) } func (t Month) TrimString() string { return strings.TrimPrefix(t.String(), "Month_") } func main() { // This example demonstrates how to use Set type. // Create new Set from values. s := set.From(Month_jan, Month_feb, Month_mar) // Set range of values to Set. s.SetRange(Month_jul, Month_oct) fmt.Println(s) }
Output: [jan feb mar jul aug sep]