set

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: BSD-3-Clause Imports: 3 Imported by: 17

README

Set

Build Status codecov Go Report Card GoDoc

Set is a simple Set data structure implementation in Go (Golang) using LinkedHashMap.

This library allow you to get a set of int64 or string without duplicated items.

Usage

package main

import (
	"fmt"

	"github.com/StudioSol/set"
)

func main() {
	duplicatedInt64 := []int64{1, 1, 2, 2, 3, 3}

	unduplicatedInt64 := set.NewLinkedHashSetINT64(duplicatedInt64...)

	// Get a []int64 from set
	unduplicatedArray := unduplicatedInt64.AsSlice()
	fmt.Println(unduplicatedArray) // will print [1 2 3]

	// Get the Length from set
	fmt.Println(unduplicatedInt64.Length()) // will print 3

	// Add new items in set
	unduplicatedInt64.Add(1, 2, 3, 4)
	fmt.Println(unduplicatedInt64.AsSlice()) // will print [1 2 3 4]

	// Check if item is in set
	fmt.Println(unduplicatedInt64.InArray(1)) // will print true
	fmt.Println(unduplicatedInt64.InArray(5)) // will print false

	// Get a []interface{} from set
	interfaceList := unduplicatedInt64.AsInterface()
	fmt.Println(interfaceList) // will print [1 2 3 4]

	// Allow to iter over set
	for i := range unduplicatedInt64.Iter() {
		fmt.Println(i)
	}

	// Remove items from set
	unduplicatedInt64.Remove(0, 1, 2, 3)
	fmt.Println(unduplicatedInt64.AsSlice()) // will print [4]
}

// You have same methods to LinkedHashSetString

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkedHashSet

type LinkedHashSet[T comparable] struct {
	// contains filtered or unexported fields
}

LinkedHashSet linked hash set implementation using linkedHashMap as its underlying data structure.

- Does not allow storing duplicated values - Does not allow storing nil values - Maintains insertion order over iteration

func NewLinkedHashSet

func NewLinkedHashSet[T comparable](items ...T) *LinkedHashSet[T]

NewLinkedHashSet returns a new LinkedHashSet with the provided items

func (*LinkedHashSet[T]) Add

func (l *LinkedHashSet[T]) Add(elements ...T)

Add adds elements to the linked hash set

func (*LinkedHashSet[T]) AsInterface

func (l *LinkedHashSet[T]) AsInterface() []interface{}

AsInterface returns a slice of all values of the linked hash set as interface{}

func (*LinkedHashSet[T]) AsSlice

func (l *LinkedHashSet[T]) AsSlice() []T

AsSlice returns a slice of all values of the linked hash set

func (*LinkedHashSet[T]) InArray

func (l *LinkedHashSet[T]) InArray(search T) bool

InArray returns whether the given item is in array or not

func (*LinkedHashSet[T]) Iter

func (l *LinkedHashSet[T]) Iter() <-chan T

Iter iterates over each element of the linked hash set

func (*LinkedHashSet[T]) Length

func (l *LinkedHashSet[T]) Length() int

Length returns the length of the linked hash set

func (*LinkedHashSet[T]) Remove

func (l *LinkedHashSet[T]) Remove(elements ...T)

Remove removes elements from the linked hash set

type LinkedHashSetINT

type LinkedHashSetINT struct {
	// contains filtered or unexported fields
}

LinkedHashSetINT linked hash set implementation using linkedHashMap as its underlying data structure.

- Does not allow storing duplicated values - Does not allow storing nil values - Maintains insertion order over iteration

func NewLinkedHashSetINT

func NewLinkedHashSetINT(ints ...int) *LinkedHashSetINT

NewLinkedHashSetINT returns a new LinkedHashSetINT with the provided items

func (*LinkedHashSetINT) Add

func (l *LinkedHashSetINT) Add(elements ...int)

Add adds elements to the linked hash set

func (*LinkedHashSetINT) AsInterface

func (l *LinkedHashSetINT) AsInterface() []interface{}

AsInterface returns a slice of all values of the linked hash set as interface{}

func (*LinkedHashSetINT) AsSlice

func (l *LinkedHashSetINT) AsSlice() []int

AsSlice returns a slice of all values of the linked hash set

func (*LinkedHashSetINT) InArray

func (l *LinkedHashSetINT) InArray(search int) bool

InArray returns whether the given item is in array or not

func (*LinkedHashSetINT) Iter

func (l *LinkedHashSetINT) Iter() <-chan int

Iter iterates over each element of the linked hash set

func (*LinkedHashSetINT) Length

func (l *LinkedHashSetINT) Length() int

Length returns the length of the linked hash set

func (*LinkedHashSetINT) Remove

func (l *LinkedHashSetINT) Remove(elements ...int)

Remove removes elements from the linked hash set

type LinkedHashSetINT64

type LinkedHashSetINT64 struct {
	// contains filtered or unexported fields
}

LinkedHashSetINT64 linked hash set implementation using linkedHashMap as its underlying data structure.

- Does not allow storing duplicated values - Does not allow storing nil values - Maintains insertion order over iteration

func NewLinkedHashSetINT64

func NewLinkedHashSetINT64(ints ...int64) *LinkedHashSetINT64

NewLinkedHashSetINT64 returns a new LinkedHashSetINT64 with the provided items

func (*LinkedHashSetINT64) Add

func (l *LinkedHashSetINT64) Add(elements ...int64)

Add adds elements to the linked hash set

func (*LinkedHashSetINT64) AsInterface

func (l *LinkedHashSetINT64) AsInterface() []interface{}

AsInterface returns a slice of all values of the linked hash set as interface{}

func (*LinkedHashSetINT64) AsSlice

func (l *LinkedHashSetINT64) AsSlice() []int64

AsSlice returns a slice of all values of the linked hash set

func (*LinkedHashSetINT64) InArray

func (l *LinkedHashSetINT64) InArray(search int64) bool

InArray returns whether the given item is in array or not

func (*LinkedHashSetINT64) Iter

func (l *LinkedHashSetINT64) Iter() <-chan int64

Iter iterates over each element of the linked hash set

func (*LinkedHashSetINT64) Length

func (l *LinkedHashSetINT64) Length() int

Length returns the length of the linked hash set

func (*LinkedHashSetINT64) Remove

func (l *LinkedHashSetINT64) Remove(elements ...int64)

Remove removes elements from the linked hash set

type LinkedHashSetString

type LinkedHashSetString struct {
	// contains filtered or unexported fields
}

LinkedHashSetString linked hash set implementation using linkedHashMap as its underlying data structure.

- Does not allow storing duplicated values - Does not allow storing nil values - Maintains insertion order over iteration

func NewLinkedHashSetString

func NewLinkedHashSetString(strings ...string) *LinkedHashSetString

NewLinkedHashSetString returns a new LinkedHashSetString with the provided items

func (*LinkedHashSetString) Add

func (l *LinkedHashSetString) Add(elements ...string)

Add adds elements to the linked hash set

func (*LinkedHashSetString) AsInterface

func (l *LinkedHashSetString) AsInterface() []interface{}

AsInterface returns a slice of all values of the linked hash set as interface{}

func (*LinkedHashSetString) AsSlice

func (l *LinkedHashSetString) AsSlice() []string

AsSlice returns a slice of all values of the linked hash set

func (*LinkedHashSetString) InArray

func (l *LinkedHashSetString) InArray(search string) bool

InArray returns whether the given item is in array or not

func (*LinkedHashSetString) Iter

func (l *LinkedHashSetString) Iter() <-chan string

Iter iterates over each element of the linked hash set

func (*LinkedHashSetString) Length

func (l *LinkedHashSetString) Length() int

Length returns the length of the linked hash set

func (*LinkedHashSetString) Remove

func (l *LinkedHashSetString) Remove(elements ...string)

Remove removes elements from the linked hash set

Jump to

Keyboard shortcuts

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