MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Intersection

Method Intersection

structure/set/set.go:126–142  ·  view source on GitHub ↗
(st2 Set[T])

Source from the content-addressed store, hash-verified

124}
125
126func (st *set[T]) Intersection(st2 Set[T]) Set[T] {
127 intersectionSet := New[T]()
128 var minSet, maxSet Set[T]
129 if st.Len() > st2.Len() {
130 minSet = st2
131 maxSet = st
132 } else {
133 minSet = st
134 maxSet = st2
135 }
136 for _, item := range minSet.GetItems() {
137 if maxSet.In(item) {
138 intersectionSet.Add(item)
139 }
140 }
141 return intersectionSet
142}
143
144func (st *set[T]) Difference(st2 Set[T]) Set[T] {
145 differenceSet := New[T]()

Callers

nothing calls this directly

Calls 5

LenMethod · 0.95
LenMethod · 0.65
GetItemsMethod · 0.65
InMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected