{"id":13645275,"url":"https://github.com/oleiade/lane","last_synced_at":"2025-05-15T04:04:26.154Z","repository":{"id":57479861,"uuid":"12426609","full_name":"oleiade/lane","owner":"oleiade","description":"Generic PriorityQueues, Queues, Stacks, and Deque data structures for Go","archived":false,"fork":false,"pushed_at":"2023-05-27T15:00:45.000Z","size":120,"stargazers_count":891,"open_issues_count":9,"forks_count":78,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-09T05:04:06.219Z","etag":null,"topics":["data-structures","deque","generic","go","priority-queue","queue","stack"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/oleiade/lane#pkg-types","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/oleiade.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}},"created_at":"2013-08-28T06:42:53.000Z","updated_at":"2025-04-28T01:12:21.000Z","dependencies_parsed_at":"2022-09-10T04:25:40.192Z","dependency_job_id":"7ba0e564-6eea-4785-985a-74a9a64d1744","html_url":"https://github.com/oleiade/lane","commit_stats":{"total_commits":89,"total_committers":11,"mean_commits":8.090909090909092,"dds":0.5730337078651686,"last_synced_commit":"75263a3c97a95d7fafc8992182b94909d8640d17"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Flane","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Flane/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Flane/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oleiade%2Flane/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oleiade","download_url":"https://codeload.github.com/oleiade/lane/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253377021,"owners_count":21898934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["data-structures","deque","generic","go","priority-queue","queue","stack"],"created_at":"2024-08-02T01:02:32.712Z","updated_at":"2025-05-15T04:04:26.100Z","avatar_url":"https://github.com/oleiade.png","language":"Go","readme":"# Lane\n\n[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)\n[![Build Status](https://github.com/oleiade/lane/actions/workflows/go.yml/badge.svg)](https://github.com/oleiade/lane/actions/workflows/go.yml)\n[![Go Documentation](https://pkg.go.dev/badge/github.com/oleiade/lane/v2#pkg-types.svg)](https://pkg.go.dev/github.com/oleiade/lane/v2#pkg-types)\n[![Go Report Card](https://goreportcard.com/badge/github.com/oleiade/lane)](https://goreportcard.com/report/github.com/oleiade/lane)\n![Go Version](https://img.shields.io/github/go-mod/go-version/oleiade/lane)\n\nThe Lane package provides textbook implementations of generic `Queue`, `PriorityQueue`, `Stack`, and `Deque` data structures. Its design focuses on simplicity, performance, and concurrent usage.\n\n\u003c!-- toc --\u003e\n\n- [Lane](#lane)\n  - [Installation](#installation)\n    - [Using `v2` releases](#using-v2-releases)\n    - [Using `v1` releases](#using-v1-releases)\n  - [Usage/Examples](#usageexamples)\n    - [Priority queue](#priority-queue)\n      - [Example](#example)\n    - [Deque](#deque)\n      - [Deque example](#deque-example)\n    - [Queue](#queue)\n      - [Queue example](#queue-example)\n    - [Stack](#stack)\n      - [Stack example](#stack-example)\n  - [Performance](#performance)\n  - [Documentation](#documentation)\n  - [License](#license)\n\n## Installation\n\nUsing this package requires a working Go environment. [See the install instructions for Go](http://golang.org/doc/install.html).\n\nThis package requires a modern version of Go supporting modules: [see the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).\n\n### Using `v2` releases\n\n```bash\ngo get github.com/oleiade/lane/v2\n```\n\n```go\n...\nimport (\n \"github.com/oleiade/lane/v2\"\n)\n...\n```\n\n### Using `v1` releases\n\n```bash\ngo get github.com/oleiade/lane\n```\n\n```go\n...\nimport (\n \"github.com/oleiade/lane\"\n)\n...\n```\n\n## Usage/Examples\n\n### Priority queue\n\n`PriorityQueue` implements a _heap priority queue_ data structure. It can be either max (descending) or min (ascending) ordered. Every operation on a `PriorityQueue` is  goroutine-safe. It performs `Push` and `Pop` operations in *O(log N)* time.\n\n#### Example\n\n```go\n// Create a new max ordered priority queue\npriorityQueue := NewMaxPriorityQueue[string, int]()\n\n// And push some prioritized content into it\npriorityQueue.Push(\"easy as\", 3)\npriorityQueue.Push(\"123\", 2)\npriorityQueue.Push(\"do re mi\", 4)\npriorityQueue.Push(\"abc\", 1)\n\n// Take a look at the min element in\n// the priority queue\nheadValue, headPriority, ok := priorityQueue.Head()\nif ok {\n    fmt.Println(headValue)    // \"abc\"\n    fmt.Println(headPriority) // 1\n}\n\n// The operations seem to preserve the song order\njacksonFive := make([]string, priorityQueue.Size())\n\nfor i := 0; i \u003c len(jacksonFive); i++ {\n    value, _, _ := priorityQueue.Pop()\n    jacksonFive[i] = value\n}\n\nfmt.Println(strings.Join(jacksonFive, \" \"))\n```\n\n### Deque\n\nDeque implements a _head-tail linked list data_ structure. Built upon a doubly linked list container, every operation performed on a `Deque` happen in *O(1)* time complexity. Every operation on a `Deque` are goroutine-safe.\n\nUsers have the option to instantiate Deques with a limited capacity using the dedicated `NewBoundDeque` constructor. When a bound Deque is full, the `Append` and `Prepend` operations fail.\n\n#### Deque example\n\n```go\n// Create a new Deque data structure\ndeque := NewDeque[string]()\n\n// And push some content into it using the Append\n// and Prepend methods\ndeque.Append(\"easy as\")\ndeque.Prepend(\"123\")\ndeque.Append(\"do re mi\")\ndeque.Prepend(\"abc\")\n\n// Take a look at what the first and\n// last element stored in the Deque are.\nfirstValue, ok := deque.First()\nif ok {\n    fmt.Println(firstValue) // \"abc\"\n}\n\nlastValue, ok := deque.Last()\nif ok {\n    fmt.Println(lastValue) // 1\n}\n\n// Use the `Pop` and `Shift`\n// methods to bring the song words together\njacksonFive := make([]string, deque.Size())\n\nfor i := 0; i \u003c len(jacksonFive); i++ {\n    value, ok := deque.Shift()\n    if ok {\n        jacksonFive[i] = value\n    }\n}\n\n// abc 123 easy as do re mi\nfmt.Println(strings.Join(jacksonFive, \" \"))\n```\n\n### Queue\n\n`Queue` is a **FIFO** (_First In First Out_) data structure implementation. Built upon a `Deque` container, it focuses its API on the following core functionalities: `Enqueue`, `Dequeue`, `Head`. Every operation on a Queue has a time complexity of *O(1)*. Every operation on a `Queue` is goroutine-safe.\n\n#### Queue example\n\n```go\n// Create a new queue and pretend to handle Starbucks clients\nqueue := NewQueue[string]()\n\n// Add the incoming clients to the queue\nqueue.Enqueue(\"grumpyClient\")\nqueue.Enqueue(\"happyClient\")\nqueue.Enqueue(\"ecstaticClient\")\n\nfmt.Println(queue.Head()) // grumpyClient\n\n// Handle the clients asynchronously\nfor {\n    client, ok := queue.Dequeue()\n    if !ok {\n        break\n    }\n\n    fmt.Println(client)\n}\n```\n\n### Stack\n\n`Stack` implements a **Last In First Out** data structure. Built upon a `Deque` container, its API focuses on the following core functionalities: `Push`, `Pop`, `Head`. Every operation on a Stack has a time complexity of *O(1)*. Every operation on a `Stack` is goroutine-safe.\n\n#### Stack example\n\n```go\n// Create a new stack and put some plates over it\nstack := NewStack[string]()\n\n// Put some plates on the stack\nstack.Push(\"redPlate\")\nstack.Push(\"bluePlate\")\nstack.Push(\"greenPlate\")\n\nfmt.Println(stack.Head()) // greenPlate\n\n// Check the top of the stack\nvalue, ok := stack.Pop()\nif ok {\n    fmt.Println(value) // greenPlate\n}\n\nstack.Push(\"yellowPlate\")\n\nvalue, ok = stack.Pop()\nif ok {\n    fmt.Println(value) // yellowPlate\n}\n\n// Check the top of the stack\nvalue, ok = stack.Pop()\nif ok {\n    fmt.Println(value) // bluePlate\n}\n\n// Check the top of the stack\nvalue, ok = stack.Pop()\nif ok {\n    fmt.Println(value) // redPlate\n}\n```\n\n## Performance\n\n```bash\ngo test -bench=.\ngoos: darwin\ngoarch: arm64\npkg: github.com/oleiade/lane/v2\nBenchmarkDequeAppend-8          22954384        54.44 ns/op      32 B/op       1 allocs/op\nBenchmarkDequePrepend-8         25097098        44.59 ns/op      32 B/op       1 allocs/op\nBenchmarkDequePop-8             63403720        18.99 ns/op       0 B/op       0 allocs/op\nBenchmarkDequeShift-8           63390186        20.88 ns/op       0 B/op       0 allocs/op\nBenchmarkDequeFirst-8           86662152        13.76 ns/op       0 B/op       0 allocs/op\nBenchmarkDequeLast-8            85955014        13.76 ns/op       0 B/op       0 allocs/op\nBenchmarkDequeSize-8            86614975        13.77 ns/op       0 B/op       0 allocs/op\nBenchmarkDequeEmpty-8           86893297        14.22 ns/op       0 B/op       0 allocs/op\nBenchmarkBoundDequeFull-8       590152324         2.039 ns/op       0 B/op       0 allocs/op\nBenchmarkBoundDequeAppend-8     64457216        18.50 ns/op       0 B/op       0 allocs/op\nBenchmarkBoundDeque-8           64631377        18.48 ns/op       0 B/op       0 allocs/op\nBenchmarkPriorityQueuePush-8    19994029        65.67 ns/op      72 B/op       1 allocs/op\nBenchmarkPriorityQueuePop-8     62751249        18.52 ns/op       0 B/op       0 allocs/op\nBenchmarkPriorityQueueHead-8    86090420        13.77 ns/op       0 B/op       0 allocs/op\nBenchmarkPriorityQueueSize-8    86768415        13.77 ns/op       0 B/op       0 allocs/op\nBenchmarkPriorityQueueEmpty-8   87036146        13.76 ns/op       0 B/op       0 allocs/op\nBenchmarkNewQueue-8             19570003        60.36 ns/op\nBenchmarkQueueEnqueue-8         25482283        46.63 ns/op      32 B/op       1 allocs/op\nBenchmarkQueueDequeue-8         63715965        18.50 ns/op       0 B/op       0 allocs/op\nBenchmarkQueueHead-8            85664312        13.79 ns/op       0 B/op       0 allocs/op\nBenchmarkNewStack-8             19925473        59.57 ns/op\nBenchmarkStackPop-8             64704993        18.80 ns/op       0 B/op       0 allocs/op\nBenchmarkStackHead-8            86119761        13.76 ns/op       0 B/op       0 allocs/op\n```\n\n## Documentation\n\nFor a more detailed overview of lane, please refer to [Documentation](https://pkg.go.dev/github.com/oleiade/lane/v2)\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Flane","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foleiade%2Flane","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foleiade%2Flane/lists"}