gxxorlist

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Overview

Example
// Create a new list and put some numbers in it.
l := New()
e4 := l.PushBack(4)
e1 := l.PushFront(1)
l.InsertBefore(3, e4)
l.InsertAfter(2, e1)

// Iterate through list and print its contents.
for e, p := l.Front(); e != nil; e, p = e.Next(p), e {
	fmt.Println(e.Value)
}
Output:

1
2
3
4

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func OutputElem

func OutputElem(e *XorElement)

func OutputList

func OutputList(l *XorList)

Iterate through list and print its contents.

func OutputListR

func OutputListR(l *XorList)

Iterate through list and print its contents in reverse.

Types

type XorElement

type XorElement struct {
	// Compute the bitwise XOR of this element's previous
	// element's address and its next element's address
	// and @PN stores the result
	PN uintptr

	// The value stored with this element.
	Value interface{}
}

XorElement is an element of a xor-linked list.

func (*XorElement) Next

func (e *XorElement) Next(prev *XorElement) *XorElement

Next returns the next list element or nil.

func (*XorElement) Prev

func (e *XorElement) Prev(next *XorElement) *XorElement

Prev returns the previous list element or nil.

type XorList

type XorList struct {
	// contains filtered or unexported fields
}

XorList represents a doubly linked list. The zero value for XorList is an empty list ready to use.

func New

func New() *XorList

New returns an initialized list.

func (*XorList) Back

func (l *XorList) Back() (back, tail *XorElement)

Back returns the last element of list l or nil.

func (*XorList) Front

func (l *XorList) Front() (front, head *XorElement)

Front returns the first element of list l or nil.

func (*XorList) Init

func (l *XorList) Init() *XorList

Init initializes or clears list l.

func (*XorList) InsertAfter

func (l *XorList) InsertAfter(v interface{}, mark *XorElement) *XorElement

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified.

func (*XorList) InsertBefore

func (l *XorList) InsertBefore(v interface{}, mark *XorElement) *XorElement

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified.

func (*XorList) Len

func (l *XorList) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*XorList) MoveAfter

func (l *XorList) MoveAfter(e, mark *XorElement)

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified.

func (*XorList) MoveBefore

func (l *XorList) MoveBefore(e, mark *XorElement)

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified.

func (*XorList) MoveToBack

func (l *XorList) MoveToBack(e *XorElement)

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified.

func (*XorList) MoveToFront

func (l *XorList) MoveToFront(e *XorElement)

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified.

func (*XorList) Output added in v0.2.0

func (l *XorList) Output()

just for test

func (*XorList) PushBack

func (l *XorList) PushBack(v interface{}) *XorElement

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*XorList) PushBackList

func (l *XorList) PushBackList(other *XorList)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other may be the same.

func (*XorList) PushFront

func (l *XorList) PushFront(v interface{}) *XorElement

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*XorList) PushFrontList

func (l *XorList) PushFrontList(other *XorList)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other may be the same.

func (*XorList) Remove

func (l *XorList) Remove(e *XorElement) interface{}

Remove removes e from l if e is an element of list l. It returns the element value e.Value.

Jump to

Keyboard shortcuts

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