Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabienjuif/go-linkedlist
Simple LinkedList in Go
https://github.com/fabienjuif/go-linkedlist
go linkedlist simple threadsafe
Last synced: 2 days ago
JSON representation
Simple LinkedList in Go
- Host: GitHub
- URL: https://github.com/fabienjuif/go-linkedlist
- Owner: fabienjuif
- Created: 2023-02-05T19:58:57.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-05T20:02:40.000Z (almost 2 years ago)
- Last Synced: 2024-12-07T11:32:32.129Z (5 days ago)
- Topics: go, linkedlist, simple, threadsafe
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-repositories - fabienjuif/go-linkedlist - Simple LinkedList in Go (Go)
README
# go-linkedlist
![build & test](https://github.com/fabienjuif/go-linkedlist/actions/workflows/simple.yml/badge.svg)
> Simple LinkedList in Go
## Install
```sh
go get github.com/fabienjuif/go-linkedlist
```## Thread safety
The Linked List is thread safe but the Iterator is not.
If you update the Linked List while Iterate over it you may notice strange behaviour.
## Example
```golang
package mainimport (
"fmt""github.com/fabienjuif/go-linkedlist"
)type Song struct {
title string
artist string
}func main() {
// best 2000 rock songs according to https://us.napster.com/blog/post/the-50-best-rock-songs-of-2000
ll := linkedlist.NewLinkedList[Song]()
ll.Append(&Song{
title: "Californication",
artist: "Red Hot Chili Peppers",
})
ll.Append(&Song{
title: "It's My Life",
artist: "Bon Jovi",
})
ll.Append(&Song{
title: "Beautiful Day",
artist: "U2",
})fmt.Println("iterate in order")
iterator := ll.NewIterator()
for iterator.Next() {
fmt.Printf("%v\n", iterator.Get())
}fmt.Println("\niterate in reverse order")
iterator = ll.NewIterator()
for iterator.Prev() {
fmt.Printf("%v\n", iterator.Get())
}
}
``````txt
iterate in order
&{Californication Red Hot Chili Peppers}
&{It's My Life Bon Jovi}
&{Beautiful Day U2}iterate in reverse order
&{Beautiful Day U2}
&{It's My Life Bon Jovi}
&{Californication Red Hot Chili Peppers}
```