Skip to content
/ set Public

An implementation of the set type in golang.

License

Notifications You must be signed in to change notification settings

wdlea/set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

set

An implementation of the set type in golang.

Example

package main

import "github.com/wdlea/set"

const SET_SIZE uint64 = 1024

type YourSetType struct{
	value uint64
}

func (t YourSetType) Hash(size uint64) uint64{ //define the Hash function to fulfil interface
	return t.value % size //the returned value MUST be less than the size parameter
}

func main(){
	s := set.MakeSet[YourSetType](SET_SIZE)//create a new set with the given type and size

	VALUE1 := YourSetType{
		value: 100,
	}
	
	//adds an item to the set
	s.Push(VALUE1)

	//Has and Pop return whether the item was in the set
	s.Has(VALUE1)//true

	//Pop removes the item
	s.Pop(VALUE1)//true

	//Meaning that any subsequent calls to either will return false
	s.Has(VALUE1)//false
	s.Pop(VALUE1)//false, note that this DOES NOT panic
	
}

About

An implementation of the set type in golang.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages