glist

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

GList: golang generics list type (go语言泛型列表)

功能齐全的泛型列表

type GElement
    func (p *GElement[T]) NextElement() *GElement[T]
    func (p *GElement[T]) PreElement() *GElement[T]
    func (p *GElement[T]) Value() T
type GList
    func NewGList[T comparable]() *GList[T]
    func (p *GList[T]) Add(item T)
    func (p *GList[T]) AddUnique(item T)
    func (p *GList[T]) Append(item T)
    func (p *GList[T]) AppendUnique(item T)
    func (p *GList[T]) Clear()
    func (p *GList[T]) Empty() bool
    func (p *GList[T]) Front() *GElement[T]
    func (p *GList[T]) Insert(item T, pos *GElement[T])
    func (p *GList[T]) Range() iter.Seq[T]
    func (p *GList[T]) Remove(e *GElement[T])
    func (p *GList[T]) SearchAll(item T) []*GElement[T]
    func (p *GList[T]) SearchOne(item T) *GElement[T]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GElement

type GElement[T comparable] struct {
	Data T
	Pre  *GElement[T]
	Next *GElement[T]
}

generics element type of GList

func (*GElement[T]) NextElement

func (p *GElement[T]) NextElement() *GElement[T]

if current element is the last one, will return nil

func (*GElement[T]) PreElement

func (p *GElement[T]) PreElement() *GElement[T]

if current element is the last one, will return nil

func (*GElement[T]) Value

func (p *GElement[T]) Value() T

return element value

type GList

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

generics list type

func NewGList

func NewGList[T comparable]() *GList[T]

use it like this: listNew := NewGList[TypeName]()

func (*GList[T]) Add

func (p *GList[T]) Add(item T)

Add: insert item at front, this is fastest

func (*GList[T]) AddUnique

func (p *GList[T]) AddUnique(item T)

AddUnique: insert item at front if it not exists.

func (*GList[T]) Append

func (p *GList[T]) Append(item T)

Append: append item at the end

func (*GList[T]) AppendUnique

func (p *GList[T]) AppendUnique(item T)

AppendUnique: first search, append at the end if not found

func (*GList[T]) Clear

func (p *GList[T]) Clear()

remove all items of the list

func (*GList[T]) Empty

func (p *GList[T]) Empty() bool

test is it empty

func (*GList[T]) Front

func (p *GList[T]) Front() *GElement[T]

get head of GList

func (*GList[T]) Insert

func (p *GList[T]) Insert(item T, pos *GElement[T])

insert item after element "pos"

func (*GList[T]) Range

func (p *GList[T]) Range() iter.Seq[T]

use it in for-range loop. usage:

for val := range list1.Range() {
	// so some thing
}

func (*GList[T]) Remove

func (p *GList[T]) Remove(e *GElement[T])

remove GLement e

func (*GList[T]) SearchAll

func (p *GList[T]) SearchAll(item T) []*GElement[T]

search all elements of GList

func (*GList[T]) SearchOne

func (p *GList[T]) SearchOne(item T) *GElement[T]

search one element of GList

Jump to

Keyboard shortcuts

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