@@ -307,18 +307,9 @@ func (s *TreeSet[T]) Contains(item T) bool {
307307 return s .locate (s .root , item ) != nil
308308}
309309
310- // ContainsSlice returns whether s contains the same set of elements that are in
311- // items. The items slice may contain duplicate elements.
312- //
313- // If the items slice is known to be set-like (no duplicates), EqualSlice provides
314- // a more efficient implementation.
310+ // ContainsSlice returns whether all elements in items are present in s.
315311func (s * TreeSet [T ]) ContainsSlice (items []T ) bool {
316- for _ , item := range items {
317- if ! s .Contains (item ) {
318- return false
319- }
320- }
321- return true
312+ return containsSlice (s , items )
322313}
323314
324315// Size returns the number of elements in s.
@@ -483,11 +474,31 @@ func (s *TreeSet[T]) EqualSet(col Collection[T]) bool {
483474}
484475
485476// EqualSlice returns whether s and items contain the same elements.
477+ //
478+ // The items slice may contain duplicates.
479+ //
480+ // If the items slice is known to contain no duplicates, EqualSliceSet may be
481+ // used instead as a faster implementation.
482+ //
483+ // To detect if a slice is a subset of s, use ContainsSlice.
486484func (s * TreeSet [T ]) EqualSlice (items []T ) bool {
485+ other := TreeSetFrom [T ](items , s .comparison )
486+ return s .Equal (other )
487+ }
488+
489+ // EqualSliceSet returns whether s and items contain exactly the same elements.
490+ //
491+ // If items contains duplicates EqualSliceSet will return false. The elements of
492+ // items are assumed to be set-like. For comparing s to a slice that may contain
493+ // duplicate elements, use EqualSlice instead.
494+ //
495+ // To detect if a slice is a subset of s, use ContainsSlice.
496+ func (s * TreeSet [T ]) EqualSliceSet (items []T ) bool {
497+ // TODO optimize
487498 if s .Size () != len (items ) {
488499 return false
489500 }
490- return s .ContainsSlice (items )
501+ return s .EqualSlice (items )
491502}
492503
493504// String creates a string representation of s, using "%v" printf formatting
0 commit comments