English | 中文
A generic doubly-linked list implementation in Go, providing a flexible and efficient data structure for managing ordered collections.
- Generic type support
- Doubly-linked list implementation
- Thread-safe operations
- Rich set of operations:
- PushFront/PushBack
- InsertBefore/InsertAfter
- MoveToFront/MoveToBack
- MoveBefore/MoveAfter
- Remove
- Iteration support
go get github.com/danielhookx/xcontainer/listpackage main
import "github.com/danielhookx/xcontainer/list"
func main() {
// Create a new list
l := list.New[int]()
// Add elements
l.PushBack(1)
l.PushBack(2)
l.PushBack(3)
// Iterate over elements
for e := l.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}
// Use generic iteration
for item := range l.Iter() {
fmt.Println(item)
}
}NewT *List[T]
Creates a new empty list.
PushFront(v T) *Element[T]PushBack(v T) *Element[T]InsertBefore(v T, mark *Element[T]) *Element[T]InsertAfter(v T, mark *Element[T]) *Element[T]MoveToFront(e *Element[T])MoveToBack(e *Element[T])MoveBefore(e, mark *Element[T])MoveAfter(e, mark *Element[T])Remove(e *Element[T]) TLen() intFront() *Element[T]Back() *Element[T]Iter() <-chan T
Next() *Element[T]Prev() *Element[T]Value T
This project is licensed under the BSD License - see the LICENSE file for details.