set

package
v1.202405300917.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Index

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

func Empty[V ~uint8]() Set[V]

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

func From[V ~uint8](values ...V) Set[V]

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

func (s Set[V]) AsBytes() []byte

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]) Clone

func (s Set[V]) Clone() Set[V]

Clone returns a copy of the Set.

func (Set[V]) Contains

func (s Set[V]) Contains(v V) bool

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

func (s Set[V]) ContainsAll(values ...V) bool

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

func (s Set[V]) ContainsAny(values ...V) bool

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

func (s Set[V]) First() (V, bool)

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

func (s Set[V]) Len() int

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]) Set

func (s *Set[V]) Set(values ...V)

Sets specified values to Set.

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]

func (Set[V]) String

func (s Set[V]) String() string

Renders Set in human-readable form, without `ValueTypeName_` prefixes, suitable for debugging or error messages

Jump to

Keyboard shortcuts

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