Documentation ¶
Overview ¶
Package aghalg contains common generic algorithms and data structures.
TODO(a.garipov): Update to use type parameters in Go 1.18.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntIsBefore ¶
func IntIsBefore(a, b comparable) (less bool)
IntIsBefore is a helper sort function for UniqChecker.Validate. a and b must be of type int.
func StringIsBefore ¶
func StringIsBefore(a, b comparable) (less bool)
StringIsBefore is a helper sort function for UniqChecker.Validate. a and b must be of type string.
Types ¶
type NullBool ¶ added in v0.107.8
type NullBool uint8
NullBool is a nullable boolean. Use these in JSON requests and responses instead of pointers to bool.
func BoolToNullBool ¶ added in v0.107.8
BoolToNullBool converts a bool into a NullBool.
func (NullBool) MarshalJSON ¶ added in v0.107.8
MarshalJSON implements the json.Marshaler interface for NullBool.
func (NullBool) String ¶ added in v0.107.8
String implements the fmt.Stringer interface for NullBool.
func (*NullBool) UnmarshalJSON ¶ added in v0.107.8
UnmarshalJSON implements the json.Unmarshaler interface for *NullBool.
type UniqChecker ¶
type UniqChecker map[comparable]int64
UniqChecker allows validating uniqueness of comparable items.
func (UniqChecker) Add ¶
func (uc UniqChecker) Add(elems ...comparable)
Add adds a value to the validator. v must not be nil.
func (UniqChecker) Merge ¶
func (uc UniqChecker) Merge(other UniqChecker) (merged UniqChecker)
Merge returns a checker containing data from both uc and other.
func (UniqChecker) Validate ¶
func (uc UniqChecker) Validate(isBefore func(a, b comparable) (less bool)) (err error)
Validate returns an error enumerating all elements that aren't unique. isBefore is an optional sorting function to make the error message deterministic.