Back to

Package list

Latest Go to latest

The latest major version is .

Published: May 27, 2020 | License: GPL3 | Module:


Package list provides intrusive double-linked lists.

Go standard library has container/list package which already provides double-linked lists. However in that implementation list itself is kept separate from data structures representing elements. This package provides alternative approach where elements embed necessary list heads which is sometimes more convenient, for example when one wants to move a list element in O(1) starting from pointer to just its data.

TODO doc how to get to container of list head via unsafe.OffsetOf.


type Head struct {
	// contains filtered or unexported fields

Head is a list head entry for an element in an intrusive doubly-linked list.

Zero HEAD value is NOT valid - always call Init() to initialize a head before using it.

func (*Head) Delete

func (h *Head) Delete()

Delete deletes h from its list.

func (*Head) Init

func (h *Head) Init()

Init initializes a head making it point to itself via .next and .prev .

func (*Head) MoveBefore

func (a *Head) MoveBefore(b *Head)

MoveBefore moves a to be before b.

XXX ok to move if a was not previously on the list?

func (*Head) Next

func (h *Head) Next() *Head

func (*Head) Prev

func (h *Head) Prev() *Head

Package Files

  • list.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier