Documentation
¶
Overview ¶
package set implements a Set using a golang map. This implies that only the types that are accepted as valid map keys can be used as set elements. For instance, do not try to Add a slice, or the program will panic.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] interface { // Add: adds new element to the set Add(item T) // Delete: deletes the passed element from the set if present Delete(item T) // Len: gives the length of the set (total no. of elements in set) Len() int // GetItems: gives the array( []T ) of elements of the set. GetItems() []T // In: checks whether item is present in set or not. In(item T) bool // IsSubsetOf: checks whether set is subset of set2 or not. IsSubsetOf(set2 Set[T]) bool // IsProperSubsetOf: checks whether set is proper subset of set2 or not. // ex: [1,2,3] proper subset of [1,2,3,4] -> true IsProperSubsetOf(set2 Set[T]) bool // IsSupersetOf: checks whether set is superset of set2 or not. IsSupersetOf(set2 Set[T]) bool // IsProperSupersetOf: checks whether set is proper superset of set2 or not. // ex: [1,2,3,4] proper superset of [1,2,3] -> true IsProperSupersetOf(set2 Set[T]) bool // Union: gives new union set of both sets. // ex: [1,2,3] union [3,4,5] -> [1,2,3,4,5] Union(set2 Set[T]) Set[T] // Intersection: gives new intersection set of both sets. // ex: [1,2,3] Intersection [3,4,5] -> [3] Intersection(set2 Set[T]) Set[T] // Difference: gives new difference set of both sets. // ex: [1,2,3] Difference [3,4,5] -> [1,2] Difference(set2 Set[T]) Set[T] // SymmetricDifference: gives new symmetric difference set of both sets. // ex: [1,2,3] SymmetricDifference [3,4,5] -> [1,2,4,5] SymmetricDifference(set2 Set[T]) Set[T] }
Set is an interface of possible methods on 'set'.
Example ¶
set := New(1, 2, 3) fmt.Println(set.Len()) // 3 set.Add(3) fmt.Println(set.Len()) // 3 set.Add(4) fmt.Println(set.Len()) // 4
Output: 3 3 4
Click to show internal directories.
Click to hide internal directories.