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

Overview

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
You might also like...
BTree provides a simple, ordered, in-memory data structure for Go programs.

BTree implementation for Go This package provides an in-memory B-Tree implementation for Go, useful as an ordered, mutable data structure. The API is

Bitset data structure

Your basic bit Set data structure for positive numbers A bit array, or bit set, is an efficient set data structure. It consists of an array that compa

Data structure and algorithm library for go, designed to provide functions similar to C++ STL

GoSTL English | 简体中文 Introduction GoSTL is a data structure and algorithm library for go, designed to provide functions similar to C++ STL, but more p

Data structure and relevant algorithms for extremely fast prefix/fuzzy string searching.

Trie Data structure and relevant algorithms for extremely fast prefix/fuzzy string searching. Usage Create a Trie with: t := trie.New() Add Keys with:

Generates data structure definitions from JSON files for any kind of programming language

Overview Archivist generates data structure definitions from JSON files for any kind of programming language. It also provides a library for golang to

A data structure for storing points.
A data structure for storing points.

ptree This package provides an in-memory data structure for storing points. Under the hood it stores points in a tree structure where nodes are spatia

 Data structure,Algorithms implemented in Go (for education)
Data structure,Algorithms implemented in Go (for education)

Data structure,Algorithms implemented in Go (for education) List of Content : 1. Math - 2. String - 3. Conversions - 4. Sort - 5. Search - 6. Data str

publish a tree-like data structure from a backend to a front-end

tree-publish publish a tree-like data structure from a backend to a front-end. It needs to be a tree in order to publish the data as JSON document. If

Data Structure Series: Heaps and heap applications

heaps Data Structure Series: Heaps and heap applications Current Updates: GO: heaps.go: max-heap implementation standard add, remove, and restore func

Comments
  • Contributor's credits

    Contributor's credits

    I don't know if the company is obliged to, but I think it is of good taste to give credit to the original contributors when publishing code. Even though the code is old and the person it is not a employee of the company anymore.

    opened by brunomvsouza 2
  • refactor: generic hash set

    refactor: generic hash set

    I had trouble getting the variadic parameter to work and the simplest solution I found was to change it to receive a slice.

    So references like the following will not work:

    linkedHashSet := set.NewLinkedHashSet(1, 1, 2, 2, 3, 3)
    linkedHashSet.Add(1, 2, 3, 4)
    linkedHashSet.Remove(0, 1, 2, 3)
    

    Accepting ideas to work around it

    enhancement help wanted 
    opened by VictorAssunc 1
  • Include support to Generics

    Include support to Generics

    We can support multiple primitive types in a single data structure with the new generic interface:

    type Element interface {
        int | int64 | float | float64 | string
    }
    

    And replace the custom methods NewLinkedHashSetINT64 with NewLinkedHashSet that support multiple types.

    enhancement 
    opened by rodrigo-brito 0
Releases(v1.0.0)
  • v1.0.0(Sep 8, 2022)

    What's Changed

    • Contributors list and coverage improvements by @rodrigo-brito in https://github.com/StudioSol/set/pull/2
    • Include Go Modules support and HashSet for int type by @rodrigo-brito in https://github.com/StudioSol/set/pull/3
    • fix travis build by @guilhermehubner in https://github.com/StudioSol/set/pull/5
    • build(ci): setup github actions / remove covey by @rodrigo-brito in https://github.com/StudioSol/set/pull/6
    • feat(generics): Adiciona suporte ao generics by @ftcRibeiro in https://github.com/StudioSol/set/pull/9

    New Contributors

    • @rodrigo-brito made their first contribution in https://github.com/StudioSol/set/pull/2
    • @guilhermehubner made their first contribution in https://github.com/StudioSol/set/pull/5
    • @ftcRibeiro made their first contribution in https://github.com/StudioSol/set/pull/9

    Full Changelog: https://github.com/StudioSol/set/commits/v1.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Studio Sol Comunicação Digital Ltda
Studio Sol Comunicação Digital Ltda
Disjoint Set data structure implementation in Go

dsu Implementation of the Disjoint-Set data structure. The Disjoint-Set, Also called a Union-Find or Merge-Find set, is a data structure that stores a

Iheb Haboubi 7 Aug 10, 2022
Probabilistic set data structure

Your basic Bloom filter Golang probabilistic set data structure A Bloom filter is a fast and space-efficient probabilistic data structure used to test

Algorithms to Go 73 Jul 6, 2022
Set data structure for Go

Archived project. No maintenance. This project is not maintained anymore and is archived.. Please create your own map[string]Type or use one of the ot

Fatih Arslan 652 Sep 15, 2022
Set data structure for Go

Archived project. No maintenance. This project is not maintained anymore and is archived.. Please create your own map[string]Type or use one of the ot

Fatih Arslan 653 Sep 5, 2022
A bloom filter is a probabilistic data structure that is used to determine if an element is present in a set

A Go implementation of a bloom filter, with support for boltdb and badgerdb as optional in-memory persistent storage.

Samsondeen 26 Jul 4, 2022
Recursively searches a map[string]interface{} structure for another map[string]interface{} structure

msirecurse Recursively searches a map[string]interface{} structure for existence of a map[string]interface{} structure Motivation I wrote this package

Fred Moyer 1 Mar 3, 2022
Trie data structure implementation in Golang 🌳

Gotri Gotri is an Unicode character based Trie/prefix tree implementation in Go, with the suggestion/auto-complete feature for character searching. Si

Monir Zaman 9 Jun 17, 2022
Data Structure Libraries and Algorithms implementation

Algorithms Data Structure Libraries and Algorithms implementation in C++ Disclaimer This repository is meant to be used as a reference to learn data s

Priyank Chheda 640 Sep 17, 2022
Go implementation of the van Emde Boas tree data structure: Priority queue for positive whole numbers in O(log log u) time.

vEB Go implementation of the van Emde Boas tree data structure: Priority queue for positive whole numbers in O(log log u) time. Supports the following

null 4 Mar 7, 2022
Implementation of the MaxStack Data Structure in Go

MaxStack-Golang Implementation of the MaxStack Data Structure in Go This repository contains the design of a max stack data structure that supports th

Girish P Mallya 0 Nov 10, 2021