{"id":24603926,"url":"https://github.com/valdotle/bit","last_synced_at":"2025-03-18T08:43:51.093Z","repository":{"id":197817333,"uuid":"699407548","full_name":"valdotle/bit","owner":"valdotle","description":"go module for basic bit operations on bitfields allowing various input type combinations","archived":false,"fork":false,"pushed_at":"2023-10-02T22:02:27.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T15:16:27.439Z","etag":null,"topics":["bit","bitfield","go","golang"],"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/valdotle.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":"2023-10-02T15:15:25.000Z","updated_at":"2023-10-02T22:04:24.000Z","dependencies_parsed_at":"2023-10-02T21:09:23.565Z","dependency_job_id":null,"html_url":"https://github.com/valdotle/bit","commit_stats":null,"previous_names":["valdotle/bit"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valdotle%2Fbit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valdotle%2Fbit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valdotle%2Fbit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valdotle%2Fbit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valdotle","download_url":"https://codeload.github.com/valdotle/bit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244188537,"owners_count":20412977,"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":["bit","bitfield","go","golang"],"created_at":"2025-01-24T15:16:32.322Z","updated_at":"2025-03-18T08:43:51.069Z","avatar_url":"https://github.com/valdotle.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/valdotle/bit.svg)](https://github.com/valdotle/bit)\n[![GoDoc reference example](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/valdotle/bit)\n[![GoReportCard example](https://goreportcard.com/badge/github.com/valdotle/bit)](https://goreportcard.com/report/github.com/valdotle/bit)\n[![GitHub license](https://badgen.net/github/license/valdotle/bit)](https://github.com/valdotle/bit/blob/main/LICENSE)\n[![Github tag](https://badgen.net/github/tag/valdotle/bit)](https://github.com/valdotle/bit/tags/)\n\nModule **bit** comes with a variety of utility functions for use with **bitfields**.\n\nThe module offers functionality for use with go built-in types (`string`, `int` and `big.Int`) as well as aliases for these types to use methods instead.\n\nThe module exposes variations of the following functions:\n\n```go\n    Has() bool // whether a bitfield includes the flag specified; always only returns a boolean\n    Add()      // add a flag to a bitfield (set corresponding bit to 1 / true)\n    Flip()     // flip a flag's state in a bitfield (flip corresponding bit)\n    Remove()   // remove a flag from a bitfield (set corresponding bit to 0 / false)\n```\n\nNote that all functions' (except for `Has()`) return value matches the type of the bitfield. This means, that methods defined on an alias type bitfield return a bitfield of that alias type as well.\n\nThe combination of **import path** and function / method **suffix** determines the data type of the bitfield and flag. This is explained in more detail below. **`int` is assumed as the default / most common bitfield type and thus doesn't need to be explicitly specified.** Bitfields of type `string` and `big.Int` are intended to be used where integer limitations are exceeded and **only then**. Since no checks are performed whether a string or bigint passed actually has to be handled as such, all string and bigint related functions **always** use `math/big`'s `big.Int` and thus have a significantly slower performance. \n\nThe **import path** determines the type of the bitfield:\n\n```go\n    import (\n        \"github.com/valdotle/bit/field\"                    // bitfield of type int - Note how it's not \"bit/field/int\"\n        stringfield \"github.com/valdotle/bit/field/string\" // bitfield of type string\n        \"github.com/valdotle/bit/field/big\"                // bitfield of type big.Int\n    )\n\n    flag := 2\n    field.Has(9, flag)           // false\n\n    stringfield.Has(\"9\", flag)   // false\n\n    big.Has(big.NewInt(9), flag) // false\n```\n\n**Methods** are defined at the parent folder of the corresponding function and are implemented as aliases:\n\n```go\n    import (\n        \"github.com/valdotle/bit\"       // methods for bitfield of type alias int\n        \"github.com/valdotle/bit/field\" // functions for bitfield of type int\n    )\n\n    flag := 2\n    field.Has(9, flag)     // false\n\n    bit.Field(9).Has(flag) // false\n```\n\nAdditionally, function and method name **suffixes** determine the flag's type:\n\n```go\n    import stringfield \"github.com/valdotle/bit/field/string\"\n\n    field := \"9\"\n\n    stringfield.Has(field, 2)                // flag of type int\n\n    stringfield.HasString(field, \"2\")        // flag of type string\n\n    stringfield.HasBig(field, big.NewInt(2)) // flag of type big.Int\n```\n\nNote, that **`int` bitfields don't allow checking against flags of type `string` or `big.Int`** (meaning they don't expose `HasString()` nor `HasBig()`) as those are intended to be used where integer limitations are exceeded and as such can't be parsed as integers anymore.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaldotle%2Fbit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaldotle%2Fbit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaldotle%2Fbit/lists"}