{"id":23508756,"url":"https://github.com/lovasko/m_bit_set","last_synced_at":"2025-05-13T15:34:51.203Z","repository":{"id":36424144,"uuid":"40729133","full_name":"lovasko/m_bit_set","owner":"lovasko","description":"C89 Small Integer Set","archived":false,"fork":false,"pushed_at":"2016-03-07T01:42:40.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T19:48:24.778Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovasko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-14T18:01:56.000Z","updated_at":"2016-08-08T23:58:02.000Z","dependencies_parsed_at":"2022-09-03T10:30:20.481Z","dependency_job_id":null,"html_url":"https://github.com/lovasko/m_bit_set","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/lovasko%2Fm_bit_set","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fm_bit_set/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fm_bit_set/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovasko%2Fm_bit_set/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovasko","download_url":"https://codeload.github.com/lovasko/m_bit_set/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253970664,"owners_count":21992541,"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-12-25T11:32:01.301Z","updated_at":"2025-05-13T15:34:51.136Z","avatar_url":"https://github.com/lovasko.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# m_smallintset\nInteger set implementation with the upper bound of 65536.\n\n## Features\n### Addition and removal\nIn order to add (or remove) integers, use the `m_smallintset_add` (or\n`m_smallintset_remove`) functions. Both manipulation functions have an `_all`\nversion that adds (or removes) all integers within the range `0..65535`.\n\n### Presence test\nTo check if a certain integer is a member of the set, use the\n`m_smallintset_contains` function. In case of a successful hit, the\n`M_SMALLINTSET_TRUE` is returned, `M_SMALLINTSET_FALSE` otherwise.\n\n### Set operations\n#### Union \u0026 intersection\nTo perform the binary union (or intersect) operation, use the\n`m_smallintset_union` (or `m_smallintset_intersect`) function. Both functions \ntake two arguments - a `m_smallintset` instances - and store the result of the\noperation into the first argument.\n\n#### Complement\nUsing the `m_smallintset_complement` function, all every membership becomes\nnegated and therefore a set complement is created. This function modifies the\n`m_smallintset` in question.\n\n## Design\nInternally, `m_smallintset` stores the presence of an integer as a single bit\ninside an array. Since the library poses a limit on the upper bound of the\nintegers, we can compute the number of bytes needed: `65536 / 8 = 8192`.\n\n## Performance\nThe library is written with performance in mind. All necessary memory is\npre-allocated in the `m_smallintset_init` function. The following benchmark\nruns the `m_smallintset_contains` function `100000000` times and computes the\ntime necessary to perform the lookups in microseconds.\n\n```C\n#include \u003csys/time.h\u003e\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cm_smallintset.h\u003e\n\n#define LOOPS 100000000\n\nint\nmain(void)\n{\n\tuint32_t i;\n\tstruct m_smallintset sis;\n\tuint64_t cnt;\n\tstruct timeval start;\n\tstruct timeval end;\n\tuint64_t diff;\n\n\tm_smallintset_init(\u0026sis);\n\n\tfor (i = 0; i \u003c 0xfff; i++)\n\t\tm_smallintset_add(\u0026sis, (uint16_t)(rand() % 0xffff));\n\n\tgettimeofday(\u0026start, NULL);\n\tfor (i = 0; i \u003c LOOPS; i++)\n\t\tif (m_smallintset_contains(\u0026sis, (uint16_t)(i % 0xffff)) == M_SMALLINTSET_TRUE)\n\t\t\tcnt++;\n\tgettimeofday(\u0026end, NULL);\n\n\tdiff = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);\n\tprintf(\"cnt = %llu\\n\", cnt);\n\tprintf(\"diff = %llu\\n\", diff);\n}\n```\nTODO what are the times, -O3, does LLVM Polly help? does it actually perform\nthe lookups? Does it use SIMD instructions on x86 or ARM?\n\n## Memory consumption\nAfter a call to the `m_smallintset_init` function, a `m_smallintset` takes\nexactly 8192 bytes of memory plus `O(1)` of additional space, making the data\nstructure _implicit_. This space is always constant and does not depend on the\nnumber of integers stored in the set.\n\n## Build\n```\n$ ninja\n```\n\n## Supported platforms\n * FreeBSD 10.0 with Clang 3.3\n * OS X 10.9 with Clang 3.5\n * Linux Gentoo 2.2 with Clang 3.6\n\nIf a platform does not appear to be in the previous list, it does not mean that\n`m_smallintset` will not work in such environment. It only means that nobody\ntested it - you are encouraged to do so and report either success or failure.\n\n## License\n2-clause BSD license. For more information please consult the\n[LICENSE](LICENSE.md) file. In the case that you need a different license, feel\nfree to contact me.\n\n## Author\nDaniel Lovasko daniel.lovasko@gmail.com\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fm_bit_set","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovasko%2Fm_bit_set","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovasko%2Fm_bit_set/lists"}