uniqlist

package module
v0.0.0-...-c8ba9e2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 2 Imported by: 0

README

uniqlist GoDoc codecov

A list contains only unique elements

Usage

l := uniqlist.New()
l.PushBack(1)         /// [ 1 ]
l.PushBack("foo")     /// [ 1, "foo" ]
l.PushFront("front")  /// [ "front", 1, "foo"]
l.Remove(1)           /// [ "front", "foo"]
a := l.PopBack()      /// a == "front". List is now ["foo"]

Traverse

for elem := l.List.Front(); elem != nil; elem = elem.Next() {
    var v interface{}
    v = elem.Value
}

Goroutine Safe

Traverse list is not goroutine safe.

Goroutine safe functions:

New()
PushBack()
PushFront()
PopBack()
PopFront()
Remove()
Len()

Benchmarks

BenchmarkPushBack-12                 	 2082919	       578 ns/op
BenchmarkPushFront-12                	 2275348	       543 ns/op
BenchmarkPushBackIgnore-12           	 2297386	       522 ns/op
BenchmarkPopBack-12                  	 6493636	       198 ns/op
BenchmarkPopFront-12                 	 6493476	       203 ns/op
BenchmarkRemove-12                   	 5808315	       223 ns/op
BenchmarkContainerListPushBack-12    	 8317676	       125 ns/op
BenchmarkContainerListRemove-12      	135425845	        10.3 ns/op
BenchmarkMapPush-12                  	 3209070	       340 ns/op
BenchmarkMapRemove-12                	 8979912	       166 ns/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UniqList

type UniqList struct {
	Map  map[interface{}]*list.Element
	List list.List
	// contains filtered or unexported fields
}

func New

func New() *UniqList

func (*UniqList) Len

func (t *UniqList) Len() int

Get the length of the list

func (*UniqList) PopBack

func (t *UniqList) PopBack() interface{}

Get the last element and remove it from list

func (*UniqList) PopFront

func (t *UniqList) PopFront() interface{}

Get the first element and remove it from list

func (*UniqList) PushBack

func (t *UniqList) PushBack(v interface{}) interface{}

Push an element to the end of the list. If the element is already in the list, it will be move to the end of the list.

func (*UniqList) PushBackIgnore

func (t *UniqList) PushBackIgnore(v interface{})

Push an element to the end of the list. If the element is already in the list, this func do nothing.

func (*UniqList) PushFront

func (t *UniqList) PushFront(v interface{})

Push an element to the front of the list. If the element is already in the list, it will be move to the front of the list.

func (*UniqList) PushFrontIgnore

func (t *UniqList) PushFrontIgnore(v interface{})

Push an element to the front of the list. If the element is already in the list, this func do nothing.

func (*UniqList) Remove

func (t *UniqList) Remove(v interface{})

Remove an element from the list.

Jump to

Keyboard shortcuts

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