{"id":17321825,"url":"https://github.com/earthboundkid/bytemap","last_synced_at":"2025-03-22T19:33:01.099Z","repository":{"id":65518396,"uuid":"593756609","full_name":"earthboundkid/bytemap","owner":"earthboundkid","description":"Bytemap contains types for making maps from bytes to bool, integer, or float using a backing array","archived":false,"fork":false,"pushed_at":"2024-08-26T14:55:12.000Z","size":551,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-16T13:39:42.847Z","etag":null,"topics":["bytemap","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"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/earthboundkid.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,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"carlmjohnson"}},"created_at":"2023-01-26T19:14:57.000Z","updated_at":"2024-08-28T18:37:15.000Z","dependencies_parsed_at":"2024-01-25T05:27:50.624Z","dependency_job_id":"61e0ae60-8b30-4916-8629-984c0d91c591","html_url":"https://github.com/earthboundkid/bytemap","commit_stats":null,"previous_names":["earthboundkid/bytemap","carlmjohnson/bytemap"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthboundkid%2Fbytemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthboundkid%2Fbytemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthboundkid%2Fbytemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/earthboundkid%2Fbytemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/earthboundkid","download_url":"https://codeload.github.com/earthboundkid/bytemap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221832475,"owners_count":16888257,"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":["bytemap","go","golang"],"created_at":"2024-10-15T13:39:50.745Z","updated_at":"2024-10-28T13:35:00.803Z","avatar_url":"https://github.com/earthboundkid.png","language":"Go","funding_links":["https://github.com/sponsors/carlmjohnson"],"categories":[],"sub_categories":[],"readme":"# bytemap [![GoDoc](https://godoc.org/github.com/earthboundkid/bytemap?status.svg)](https://godoc.org/github.com/earthboundkid/bytemap/v2) [![Go Report Card](https://goreportcard.com/badge/github.com/earthboundkid/bytemap)](https://goreportcard.com/report/github.com/earthboundkid/bytemap) [![Coverage Status](https://coveralls.io/repos/github/earthboundkid/bytemap/badge.svg)](https://coveralls.io/github/earthboundkid/bytemap)\n\nBytemap contains types for making maps from bytes to bool, integer, or float using a backing array.\n\n## Benchmarks\n\nMicro-benchmarks are usually not a good way to evaluate systems. That said, using a bytemap array can be very fast while also providing readable code.\n\nLet's say you want to test that string contains only digits. A very fast way is just to write a loop:\n\n```go\nmatch := true\nfor _, c := range []byte(s) {\n    if c \u003c '0' || c \u003e '9' {\n        match = false\n        break\n    }\n}\n```\n\nThis is very fast, but the code is somewhat tedious. One might decide to replace it with a simple regular expression.\n\n```go\nr := regexp.MustCompile(`^[0-9]*$`)\nmatch := r.MatchString(s)\n```\n\nThis is much shorter, but it's actually a little tricky to read if you're not very familiar with regular expressions, and it's much slower to execute.\n\nAnother idea might be to test against a `map[byte]bool`. This turns out to be almost as slow as the regular expression and about as verbose as the simple loop test.\n\nA bytemap is **short, simple, and fast**:\n\n```go\nm := bytemap.Make(\"0123456789\")\nmatch := m.Contains(s)\n```\n\nTake these benchmarks with a grain of salt, but they show a bytemap can actually perform as well as a handwritten loop or better:\n\n```\ngoos: darwin\ngoarch: amd64\npkg: github.com/earthboundkid/bytemap\nBenchmarkBoolContains-8         318648963        3.762 ns/op\nBenchmarkBitFieldContains-8     216729614        5.526 ns/op\nBenchmarkLoop-8                 170478852        6.954 ns/op\nBenchmarkMapByteEmpty-8         143119087        8.991 ns/op\nBenchmarkMapByteBool-8           19294774       61.44 ns/op\nBenchmarkRegexp-8                11613380      102.7 ns/op\nBenchmarkRegexpSlow-8              822931     1289 ns/op\n```\n\n## How does it work?\n\nThere are only 256 different possible bit patterns in a byte, so `bytemap.Bool` just preallocates an array of 256 entries.\n\n`bytemap.BitField` only allocates one bit per entry, which makes it 8 times smaller than `bytemap.Bool`, only 32 bytes long. In many cases however, it will be a bit slower than using a `bytemap.Bool`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearthboundkid%2Fbytemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fearthboundkid%2Fbytemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fearthboundkid%2Fbytemap/lists"}