{"id":23508964,"url":"https://github.com/maxbolgarin/abstract","last_synced_at":"2025-05-13T15:35:56.766Z","repository":{"id":264608828,"uuid":"893400042","full_name":"maxbolgarin/abstract","owner":"maxbolgarin","description":"Generic data structures to get rid of boilerplate code in business logic","archived":false,"fork":false,"pushed_at":"2025-04-25T12:00:31.000Z","size":102,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T12:31:32.045Z","etag":null,"topics":["datastructures","generic","go","golang","library"],"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/maxbolgarin.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}},"created_at":"2024-11-24T10:54:36.000Z","updated_at":"2025-04-25T11:59:29.000Z","dependencies_parsed_at":"2025-02-12T06:35:43.715Z","dependency_job_id":"ec657610-da94-4bc0-8e62-e69a8dc4d425","html_url":"https://github.com/maxbolgarin/abstract","commit_stats":null,"previous_names":["maxbolgarin/abstract"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fabstract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fabstract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fabstract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxbolgarin%2Fabstract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxbolgarin","download_url":"https://codeload.github.com/maxbolgarin/abstract/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253971097,"owners_count":21992647,"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":["datastructures","generic","go","golang","library"],"created_at":"2024-12-25T11:36:14.001Z","updated_at":"2025-05-13T15:35:56.757Z","avatar_url":"https://github.com/maxbolgarin.png","language":"Go","funding_links":[],"categories":["Utilities","公用事业公司"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous"],"readme":"# abstract\n\n[![Go Version][version-img]][doc] [![GoDoc][doc-img]][doc] [![Build][ci-img]][ci] [![GoReport][report-img]][report]\n\n\n**`abstract` provides a suite of generic data structures to focus on the core business logic and avoid unnecessary boilerplate**\n\n```\ngo get -u github.com/maxbolgarin/abstract\n```\n\n## Overview\n\n`abstract` package provides a suite of generic data structures to enhance code organization, concurrency safety, and utility in Go. The package aims to simplify and abstract the working processes with generic and concurrent data structures such as maps, stacks, sets, and pairs. \n\n### Key Features\n- **Generic Data Structures**: Includes Map, Orderer, Stack, Set, and their thread-safe counterparts.\n- **Clean Code**: Using of this package allowes you to focus on the core business logic and avoid unnecessary complexity.\n- **Concurrency Safety**: Thread-safe structures provided for concurrent access across multiple goroutines.\n- **Ease of Use**: Designed to integrate seamlessly and abstract away complex operations into simple APIs.\n\n### Cons\n- **Complexity**: Abstraction layers might add complexity for simpler use cases.\n- **Performance Overhead**: Concurrency safety through mutexes can add overhead.\n- **Learning Curve**: Understanding generics and constraints may require additional learning.\n\n\n### Data Structures and Safe Alternatives\n\n| Data Structure | Description | Safe Alternative | Key Methods |\n|----------------|-------------|------------------|-------------|\n| `Map`          | Generic map for key-value pairs. | `SafeMap` | Get, Set, Delete, Keys, Values |\n| `EntityMap`    | Map of entities, providing ordering features. | `SafeEntityMap` | Set, Delete, AllOrdered |\n| `Set`          | Stores keys uniquely without associated values. | `SafeSet` | Add, Remove, Has |\n| `Slice`        | Generic slice implementation. | `SafeSlice` | Append, Get, Pop, Delete |\n| `Stack`        | Generic stack implementation. | `SafeStack` | Push, Pop, Last |\n| `UniqueStack`  | Stack without duplicates. | `SafeUniqueStack` | Push, Pop, Last |\n| `LinkedList`   | Generic doubly linked list implementation. | `SafeLinkedList` | Front, Back |\n| `OrderedPairs` | Maintains order of key-value pairs. | `SafeOrderedPairs` | Add, Get, Keys, Rand |\n\n\n## Usage Examples\n\n### Using Map and SafeMap\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/maxbolgarin/abstract\"\n)\n\nfunc main() {\n\t// Example using Map\n\tm := abstract.NewMap[string, int]()\n\tm.Set(\"apple\", 5)\n\tfmt.Println(m.Get(\"apple\")) // Output: 5\n\n\t// Example using SafeMap\n\tsm := abstract.NewSafeMap[string, int]()\n\tsm.Set(\"banana\", 10)\n\tfmt.Println(sm.Get(\"banana\")) // Output: 10\n}\n```\n\n### Using Stack and SafeStack\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"abstract\"\n)\n\nfunc main() {\n\t// Example using Stack\n\ts := abstract.NewStack[int]()\n\ts.Push(10)\n\tfmt.Println(s.Pop()) // Output: 10\n\n\t// Example using SafeStack\n\tss := abstract.NewSafeStack[int]()\n\tss.Push(20)\n\tfmt.Println(ss.Pop()) // Output: 20\n}\n```\n\n### Using EntityMap and SafeEntityMap\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"abstract\"\n)\n\n// Define a simple Entity type\ntype MyEntity struct {\n\tid    string\n\tname  string\n\torder int\n}\n\nfunc (e MyEntity) ID() string    { return e.id }\nfunc (e MyEntity) Name() string  { return e.name }\nfunc (e MyEntity) Order() int    { return e.order }\nfunc (e MyEntity) SetOrder(o int) abstract.Entity[string] {\n\treturn MyEntity{id: e.id, name: e.name, order: o}\n}\n\nfunc main() {\n\teMap := abstract.NewEntityMap[string, MyEntity]()\n\teMap.Set(MyEntity{id: \"1\", name: \"entity1\", order: 0})\n\tfoundEntity, ok := eMap.LookupByName(\"entity1\")\n\tif ok {\n\t\tfmt.Println(foundEntity.Name()) // Output: entity1\n\t}\n}\n```\n\n\n## Contributions and Issues\n\nFeel free to contribute to this package or report issues you encounter during usage\n\n## License\n\nThis project is licensed under the terms of the [MIT License](LICENSE).\n\n[MIT License]: LICENSE.txt\n[version-img]: https://img.shields.io/badge/Go-%3E%3D%201.23-%23007d9c\n[doc-img]: https://pkg.go.dev/badge/github.com/maxbolgarin/abstract\n[doc]: https://pkg.go.dev/github.com/maxbolgarin/abstract\n[ci-img]: https://github.com/maxbolgarin/abstract/actions/workflows/go.yaml/badge.svg\n[ci]: https://github.com/maxbolgarin/abstract/actions\n[report-img]: https://goreportcard.com/badge/github.com/maxbolgarin/abstract\n[report]: https://goreportcard.com/report/github.com/maxbolgarin/abstract\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Fabstract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxbolgarin%2Fabstract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxbolgarin%2Fabstract/lists"}