{"id":16788570,"url":"https://github.com/mna/algo","last_synced_at":"2025-04-10T23:13:32.334Z","repository":{"id":57597315,"uuid":"377517703","full_name":"mna/algo","owner":"mna","description":"Fundamental algorithms and data structures using Go generics.","archived":false,"fork":false,"pushed_at":"2021-06-21T14:01:03.000Z","size":55,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T23:13:27.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mna"],"custom":["https://www.buymeacoffee.com/mna"]}},"created_at":"2021-06-16T14:07:19.000Z","updated_at":"2022-12-12T16:15:00.000Z","dependencies_parsed_at":"2022-08-28T09:10:10.734Z","dependency_job_id":null,"html_url":"https://github.com/mna/algo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Falgo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Falgo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Falgo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mna%2Falgo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mna","download_url":"https://codeload.github.com/mna/algo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312135,"owners_count":21082638,"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":[],"created_at":"2024-10-13T08:18:19.238Z","updated_at":"2025-04-10T23:13:32.312Z","avatar_url":"https://github.com/mna.png","language":"Go","funding_links":["https://github.com/sponsors/mna","https://www.buymeacoffee.com/mna"],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/mna/algo/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/mna/algo/actions)\n[![Go Reference](https://pkg.go.dev/badge/github.com/mna/algo.svg)](https://pkg.go.dev/github.com/mna/algo)\n\n# Algo: fundamental algorithms and data structures in Go\n\nWith the Go programming language soon gaining support for [type parameters\n(_generics_)](https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md),\nit becomes interesting to implement some of the fundamental algorithms and data\nstructures not previously found in the standard library (pre Go1.18 at least)\nin a generic way - where before those would've been implemented repeatedly for\ndifferent data types, or implemented with the empty interface (`interface{}`),\nlosing type safety.\n\nEventually, I assume many of those algorithms will end up in the standard\nlibrary, but in the meantime it is a good excuse to revisit them and get a feel\nfor the generics proposal. It can also serve as a reference for implementation\nof those fundamental algorithms and data structures - I will take great care to\nmake the code clear and well documented (the goal is not to make it as fast as\npossible at the expense of code clarity, e.g. reaching for the `unsafe` package\nis likely out of scope for this package), and will mention the Big O\ncomplexities, with benchmarks to demonstrate them.\n\nThat being said, please do rise an issue or send a pull request if there is an\nobvious optimization missing or if an implementation is not quite right.\n\nOnce generics land officially (I'm not interested to make this work with the\ntemporary `go2go` compiler), I will update the code to build with the proper\nconstraints and type arguments. For now, it is a mix of inline comments and\ntype aliases to bring the syntax close to the generics one, and the generic `T`\nis aliased to `int`, e.g.:\n\n```go\n// in package search, file binary.go\n\ntype T = int\nfunc Binary /*[T algo.OrderedComparable]*/ (vals []T, v T) int {\n  ...\n}\n\n\n// in package algo, file constraints.go\n\ntype Comparable interface{}\ntype Ordered interface {\n\t/*\n\t\ttype int, int8, int16, int32, int64,\n\t\t\tuint, uint8, uint16, uint32, uint64, uintptr,\n\t\t\tfloat32, float64,\n\t\t\tstring\n\t*/\n}\ntype OrderedComparable interface {\n\tOrdered\n\tComparable\n}\n```\n\n## Installation\n\n    $ go get [-u] [-t] github.com/mna/algo\n\n## License\n\nThe [BSD 3-Clause license](http://opensource.org/licenses/BSD-3-Clause).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmna%2Falgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmna%2Falgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmna%2Falgo/lists"}