Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFullSet occurs when a `Insert()` method is called on a set // that is full. Readers must return this error as is and not wrap // it as callers are expected to check for this error with the == // operator. ErrFullSet error = errors.New("set is full") )
Functions ¶
func Equals ¶
func Equals[E comparable](s1, s2 Set[E]) bool
Equals checks if the two sets are equal. Two sets are equal if the call of IsSubset(s1, s2) and IsSubset(s2, s1) return true.
Parameters:
- s1: The first set.
- s2: The second set.
Returns:
- bool: True if the two sets are equal, false otherwise.
func Insert ¶
func Insert[E comparable](s Set[E], elems ...E) (uint32, error)
Insert adds elements to the set.
Parameters:
- s: The set to add elements to.
- elems: The elements to add.
Returns:
- uint32: The number of elements added.
- error: An error if the elements could not be added.
Errors:
- common.ErrBadParam: If the set is nil.
- common.ErrMaxSizeExceeded: If the number of elements added would exceed the maximum size of uint32.
- any other error: Depends on the implementation of the `Insert()` method.
func IsSubset ¶
func IsSubset[E comparable](s1, s2 Set[E]) bool
IsSubset checks if the first set is a subset of the second set.
Parameters:
- s1: The first set.
- s2: The second set.
Returns:
- bool: True if the first set is a subset of the second set, false otherwise.
Types ¶
type OrderSet ¶
type OrderSet[E comparable] struct { // contains filtered or unexported fields }
OrderSet is a set that keeps the order of insertion.
An empty OrderSet can be created with either the `var s OrderSet[E]` syntax or the `s := new(OrderSet[E])` constructor.
type SeenSet ¶
type SeenSet[E comparable] struct { // contains filtered or unexported fields }
SeenSet is a set can can see elements.
An empty SeenSet can be created by using either the `var s SeenSet[E]` syntax or the `s := new(SeenSet[E])` constructor.
type Set ¶
type Set[E comparable] interface { // Insert adds an element to the set. Returns false and nil if the // element is already in the set. // // Parameters: // - elem: The element to add. // // Returns: // - bool: True if the element was added, false if the element // - error: An error if the element could not be added. // // Errors: // - ErrFullSet: If the set is full. // - common.ErrNilReceiver: If the receiver is nil. // - any other error: Implementation-dependent. Insert(elem E) (bool, error) // Contains checks if the set contains the element. // // Parameters: // - elem: The element to check. // // Returns: // - bool: True if the set contains the element, false otherwise. Contains(elem E) bool // IsEmpty checks if the set is empty. // // Returns: // - bool: True if the set is empty, false otherwise. IsEmpty() bool // IsFull checks if the set is full. // // Returns: // - bool: True if the set is full, false otherwise. IsFull() bool // All returns a sequence of all elements in the set. The order of // the elements is undefined. // // Returns: // - iter.Seq[E]: A sequence of all elements in the set. Never // returns nil. All() iter.Seq[E] // Reset clears the set for reuse. // // Returns: // - error: An error if the set could not be reset. // // Errors: // - common.ErrNilReceiver: If the receiver is nil. // - any other error: Implementation-dependent. Reset() error }
Set is the interface for set-like data structures.