{"id":32948793,"url":"https://github.com/koss-null/list","last_synced_at":"2026-01-27T10:16:38.674Z","repository":{"id":256947175,"uuid":"857148414","full_name":"koss-null/list","owner":"koss-null","description":"go 1.23 implementation of linked list with iterators and generics support","archived":false,"fork":false,"pushed_at":"2025-10-25T18:40:52.000Z","size":35,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-12T22:02:50.539Z","etag":null,"topics":["generic-linked-list","golang-library","golang-package","intrusive-linked-list","iterator","linked-list","list","stdlib"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koss-null.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-13T22:55:26.000Z","updated_at":"2025-10-25T18:40:56.000Z","dependencies_parsed_at":"2024-09-14T02:51:28.201Z","dependency_job_id":"3dc0b75e-7def-46ea-a6c5-ef3fbca76069","html_url":"https://github.com/koss-null/list","commit_stats":null,"previous_names":["koss-null/list"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/koss-null/list","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koss-null%2Flist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koss-null%2Flist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koss-null%2Flist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koss-null%2Flist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koss-null","download_url":"https://codeload.github.com/koss-null/list/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koss-null%2Flist/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28811577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T07:41:26.337Z","status":"ssl_error","status_checked_at":"2026-01-27T07:41:08.776Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generic-linked-list","golang-library","golang-package","intrusive-linked-list","iterator","linked-list","list","stdlib"],"created_at":"2025-11-12T20:00:35.661Z","updated_at":"2026-01-27T10:16:38.670Z","avatar_url":"https://github.com/koss-null.png","language":"Go","readme":"# Linked List Implementation in Go\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/koss-null/list)](https://goreportcard.com/report/github.com/koss-null/list)\n[![Go Reference](https://pkg.go.dev/badge/github.com/koss-null/list.svg)](https://pkg.go.dev/github.com/koss-null/list)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Coverage](https://raw.githubusercontent.com/koss-null/list/master/coverage.svg?raw=true)](coverage.svg)\n\nThis repository contains:\n- a **generic-based**, **thread-safe** implementation of a *doubly linked list* with **iterators support**.  \n- a **generic-based** implementation of **intrusive** *singly linked list*.  \n  \nIt was created to address the lack of iterators, async and generic support in Go's default `container/list` package.  \n\n\n## Features\n\nThis linked list implementation provides the following features:\n\n- **Generics**: The linked list can store elements of any type, thanks to Go's support for generics.\n- **Iterators**: The `Begin` and `End` methods allow you to iterate over the list from the head to the tail and vice versa, respectively.\n- **Node Access**: The `Head`, `Tail`, `Next`, and `Prev` methods provide access to the nodes of the list.\n- **Node Manipulation**: The `PushBack`, `PushFront`, `PopBack`, and `PopFront` methods allow you to add and remove nodes from the list.\n- **List Information**: The `Size` and `Empty` methods provide information about the list.\n- **Intrusive List Support**: The implementation allows you to embed the linked list structure directly within your own structs, enabling efficient memory usage and manipulation without the need for separate node types.\n\n## Doubly Linked List\n  \nDoubly linked list is created with: \n  \n- `NewSyncLinked[T]()`: Creates a new **synced** linked list (all operations are blocking).\n- `list.Linked[T]{}`: Creates a new **unsynced** linked list  \n  \nHere is a list of available methods with their descriptions:\n  \n  \n- `PushBack(val T)`: Adds a new node with the given value at the end of the list.\n- `PushFront(val T)`: Adds a new node with the given value at the beginning of the list.\n- `PopBack() (T, bool)`: Removes the last node from the list and returns its value and a boolean indicating success.\n- `PopFront() (T, bool)`: Removes the first node and returns its value and a boolean indicating success.\n- `Head() *Node[T]`: Returns the first node of the list.\n- `Tail() *Node[T]`: Returns the last node of the list.\n- `Size() int`: Returns the number of nodes in the list.\n- `Empty() bool`: Checks if the list is empty.\n- `Begin(yield func(T) bool)`: Iterates over the list from the head to the tail.\n- `End(yield func(T) bool)`: Iterates over the list from the tail to the head.\n- `Val() T`: Returns the value of the node.\n- `Next() *Node[T]`: Returns the next node.\n- `Prev() *Node[T]`: Returns the previous node.\n\n## Intrusive Singly Linked List\n\nIntrusive Singly Linked List is created with: \n  \n```go\ntype S struct { // suppose this is your struct\n    a, b int // define your struct innies\n    *list.List[S] // embed the List structure inside your package\n}\n```\n  \nHere is a list of available methods with their descriptions:\n  \n  \n- `Next() *T`: returns a pointer to the next element in the linked list.\n- `SetNext(next *T)`: assigns the 'next' pointer to the provided element, effectively making 'next' the subsequent element in the list.\n- `InsertNext(elem *T)`: InsertNext() inserts the provided element 'elem' as the subsequent element in the list. The element that was previously next becomes the next element of 'elem'.\n- `RemoveNext()`: detaches the next element from the list. The element following the next element (if it exists) becomes the new next element.\n  \n## Usage Example\n  \nHere is a simple usage example: [try here](https://go.dev/play/p/xQwBpUEaT3r)\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/koss-null/list\"\n)\n\nfunc foo() {\n\t// Create a new linked list\n\tll := list.Linked[int]{}\n\n\t// Add elements to the list\n\tll.PushBack(1)\n\tll.PushBack(2)\n\tll.PushBack(3)\n\t// The list contains: 1, 2, 3\n\n\t// Print the elements of the list\n\tfor val := range ll.Begin {\n\t\tfmt.Println(val)\n\t}\n\n\t// Remove an element from the list\n\tval, ok := ll.PopBack()\n\tif ok {\n\t\tfmt.Printf(\"Popped value: %d\\n\", val)\n\t\t// Prints: Popped value: 3\n\t}\n\n\t// Print the size of the list\n\tfmt.Printf(\"List size: %d\\n\", ll.Size())\n\t// Prints: 2\n}\n```\n\n## Intrusive List Usage Example\n\nThis library also supports **intrusive** singly linked lists if you want to imbed it in your own structure. Here is the example: [try here](https://go.dev/play/p/NMTOWaMQFaY)\n\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/koss-null/list\"\n)\n\ntype S struct {\n\ta, b int\n\t*list.List[S]\n}\n\nfunc NewS(a, b int) *S {\n    return \u0026S{a: a, b: b, List: \u0026list.List[S]{}}\n}\n\nfunc foo() {\n\t// Create a new linked list\n\thead := NewS(1, 2)\n\tcur := head\n\n\t// Add elements to the list\n\tcur.SetNext(NewS(3, 4))\n\tcur = cur.Next()\n\tcur.SetNext(NewS(5, 6))\n\n\t// Print the elements of the list\n\tfor node := head; node != nil; node = node.Next() {\n\t\tfmt.Println(node.a, node.b)\n\t}\n\t// 1 2 3 4 5 6\n\n\t// Remove an element from the list\n\thead.RemoveNext()\n\n\t// Print the elements of the list after removal\n\tfor node := head; node != nil; node = node.Next() {\n\t\tfmt.Println(node.a, node.b)\n\t}\n\t// 1 2 5 6\n}\n```\n\n## Contributing \n\nContributions are welcome! Please feel free to submit a Pull Request.\n","funding_links":[],"categories":["Data Structures and Algorithms","Data Integration Frameworks","数据结构与算法"],"sub_categories":["Queues","队列"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoss-null%2Flist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoss-null%2Flist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoss-null%2Flist/lists"}