hashset

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

A hash set that uses native go map under the hood. It implements Seter and Collectioner. Set is not thread safe

func New

func New[K comparable](elements ...K) Set[K]

Creates an instance of Set with given elements and returns pointer to the instance. If no elements are given, an empty set is created. Elements must be comparable

func NewFromCollection

func NewFromCollection[K comparable](c generic.Collectioner[K]) Set[K]

Creates an instance of Set with given collection and returns pointer to the instance. Elements must be comparable

func (*Set[K]) Add

func (s *Set[K]) Add(element K) bool

Adds the given element to the Set. If the element does not exist in the Set, Add will add the given element and return true. If the element already exists in the Set, Add will not add the given element and return false. Implements Seter.Add and Collectioner.Add

func (*Set[K]) Clear

func (s *Set[K]) Clear()

Clears the current Set so it becomes empty. Under the hood, a new instance of builtin map is assigned as the new internal container Implements Seter.Clear

func (*Set[K]) Contains

func (s *Set[K]) Contains(element K) bool

Returns true when the given element exists in the Set. Implements Seter.Contains and Collectioner.Contains

func (*Set[K]) Empty

func (s *Set[K]) Empty() bool

Returns true if the Set is empty. Implements Seter.Empty and Collectioner.Empty

func (*Set[K]) Equals

func (s *Set[K]) Equals(set set.Seter[K]) bool

Returns true when the given Set has the equal members as the current Set Implements Seter.Equals

func (*Set[K]) ForEach

func (s *Set[K]) ForEach(do func(*K))

Iterates through each element in the Set and executes the given "do" function on each element. Implements Seter.ForEach and Collectioner.ForEach

func (*Set[K]) GetIntersection

func (s *Set[K]) GetIntersection(set set.Seter[K]) set.Seter[K]

Returns a new instance of Set with the common members between the current Set and the given Set. Implements Seter.GetIntersection

func (*Set[K]) GetUnion

func (s *Set[K]) GetUnion(set set.Seter[K]) set.Seter[K]

Returns a new instance of Set with all the members of both the current Set and the given Set. Implements Seter.GetUnion

func (*Set[K]) Intersects

func (s *Set[K]) Intersects(set set.Seter[K]) bool

Returns true when the given Set has common members with the current Set. Implements Seter.Intersects

func (*Set[K]) IsSubsetOf

func (s *Set[K]) IsSubsetOf(set set.Seter[K]) bool

Returns true if the given Set has all the members of the current Set. Implements Seter.IsSubsetOf

func (*Set[K]) IsSupersetOf

func (s *Set[K]) IsSupersetOf(set set.Seter[K]) bool

Returns true if the current Set contains all the members of the given Set. Implements Seter.IsSupersetOf

func (*Set[K]) Remove

func (s *Set[K]) Remove(element K) bool

Removes the given element from the Set. If the given element is found, Remove will delete the element from the Set and return true. If the given element to remove is not found in the Set, then Remove will return false. Implements Seter.Remove and Collectioner.Remove

func (*Set[K]) Size

func (s *Set[K]) Size() int

Gets the length of the Set. Implements Seter.Size and Collectioner.Size

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL