{"id":18551792,"url":"https://github.com/tomhea/farray","last_synced_at":"2025-07-16T11:06:55.254Z","repository":{"id":55867668,"uuid":"314884398","full_name":"tomhea/farray","owner":"tomhea","description":"Initialize / Fill C++ array fast - O(1) time with only 1 extra bit of memory.","archived":false,"fork":false,"pushed_at":"2023-03-04T21:22:24.000Z","size":294,"stargazers_count":30,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T14:33:00.503Z","etag":null,"topics":["array","bit","constant-space","constant-time","cpp","data-structures","header","header-only","implementation","initialization","library","o1","paper","template"],"latest_commit_sha":null,"homepage":"https://tomhea.github.io/farray/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomhea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2020-11-21T19:07:01.000Z","updated_at":"2025-01-24T21:10:32.000Z","dependencies_parsed_at":"2024-11-06T21:10:29.872Z","dependency_job_id":"3d7d773f-5bbf-45c0-90c5-91541966b6f9","html_url":"https://github.com/tomhea/farray","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/tomhea/farray","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomhea%2Ffarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomhea%2Ffarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomhea%2Ffarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomhea%2Ffarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomhea","download_url":"https://codeload.github.com/tomhea/farray/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomhea%2Ffarray/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262916575,"owners_count":23383883,"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":["array","bit","constant-space","constant-time","cpp","data-structures","header","header-only","implementation","initialization","library","o1","paper","template"],"created_at":"2024-11-06T21:10:21.380Z","updated_at":"2025-07-01T07:04:29.147Z","avatar_url":"https://github.com/tomhea.png","language":"C++","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"#readme\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/tomhea/farray/master/res/logo.png\" alt=\"Farray logo: Initialize Arrays in O(1)\" height=\"150\"\u003e\u003c/a\u003e\n\n[![Tests Badge](https://github.com/tomhea/farray/actions/workflows/tests.yml/badge.svg)](https://github.com/tomhea/farray/actions/workflows/tests.yml)\n[![GitHub file size in bytes](https://img.shields.io/github/size/tomhea/farray/include/farray1.hpp)](include/farray1.hpp)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/tomhea/farray)](https://github.com/tomhea/farray/releases/latest)\n[![GitHub](https://img.shields.io/github/license/tomhea/farray)](LICENSE)\n[![Website](https://img.shields.io/website?down_color=red\u0026down_message=down\u0026up_message=up\u0026url=https%3A%2F%2Ftomhea.github.io%2Ffarray%2F)](https://tomhea.github.io/farray/)\n\n\u003c/div\u003e\n\n## Initialize arrays in constant time\n\nC++ **Header-only** Implementation of the [In-Place Initializable Arrays](https://arxiv.org/abs/1709.08900) paper.\n\nIt's a templated array with **constant-time** fill(v), read(i), write(i,v) operations, all with just 1 bit of extra memory.\u003cbr\u003e\nYou can really [sense the **speedup**](#how-much-faster-) it provides.\n\nThis **single-file** library is [**thoroughly tested**](tests/tests_farray1.cpp), and is **Embedded-friendly** as it has no exceptions, and use no other library. It can also use no dynamic allocations.\n\nThe paper is based on the simpler [Initializing an array in constant time](https://eli.thegreenplace.net/2008/08/23/initializing-an-array-in-constant-time) - which uses 2n extra memory words.\u003cbr\u003e\nI wrote a **[Medium article](https://link.medium.com/Q8YbkDJX2bb)** about array initialization and this project. Read it and come back 🧑‍💻. \n\n# Basic Use:\nTo use the array, just [download](https://github.com/tomhea/farray/releases/latest/download/farray1.hpp) and include the header file. *That's it.*\n```c\n#include \"farray1.hpp\"\n```\n\nIf you want to compile it without any dynamic allocations:\n```c\n#define FARRAY1_NO_DYNAMIC_ALLOCATIONS\n#include \"farray1.hpp\"\n```\n\n### Using the Farray1 class:\n```c\n// initialization (all to 1s)\nFarray1\u003cint\u003e A(n, 1);   // Farray1 allocated an array be itself. \n                        // It can also take an already allocated array as a parameter.\n\n// read \u0026 write\nA[3] = 5;\nint x = A[12] + A[19] + A[3];   // reading (1+1+5)\n\ncout \u003c\u003c \"This must be seven: \" \u003c\u003c x \u003c\u003c endl;\n\n// simple initialization - all values are now 2020\nA = 2020;     \n\nfor (int i = 5; i \u003c= 10; i++)\n    A[i] = i*i;\n    \nfor (int i = 3; i \u003c= 12; i++)\n    cout \u003c\u003c A[i] \u003c\u003c \" \";\n```\n\nThe output will be:\n```\nThis must be seven: 7\n2020 2020 25 36 49 64 81 100 2020 2020 \n```\n\nYou can also use the `A.fill(v), A.read(i), A.write(i,v)` syntax, instead of `A=v, A[i], A[i]=v`.\n\nAlso, indexing is circular, so ```A[i] is A[i % n]``` (e.g ```A[2n+5] == A[5] == A[-n+5]```).\n\n# How much Faster? 🚀\n\nTake a look at the time [speedups](timings/times_farray1_output.txt) gained by using Farray1 over a regular array.\n```\nSpeedups of the average operation (read/write/fill) on Farray1/c-arrays of size 1000000:\n\nWhen 10% of the operations are array-fills:\n  Farray1\u003cint64_t, 1000000\u003e is 547 times(!) faster than int64_t[1000000].\n\nWhen 2% of the operations are array-fills:\n  Farray1\u003cint64_t, 1000000\u003e is 110 times(!) faster than int64_t[1000000].\n\nWhen Only 0.2% of the operations are array-fills:\n  Farray1\u003cint64_t, 1000000\u003e is  12 times(!) faster than int64_t[1000000].\n\nWhen Only 0.05% of the operations are array-fills:\n  Farray1\u003cint64_t, 1000000\u003e is   3 times(!) faster than int64_t[1000000].\n```\nYou can also run the timings benchmark on your pc with [times_farray1.cpp](timings/times_farray1.cpp) (takes about 5 minutes).\n\n\n\n# Farray Website!\n\nThis project has a [Website](https://tomhea.github.io/farray/)! It covers to following topics:\n* [Short Description about the algorithm](https://tomhea.github.io/farray/Short-Description.html)\n* [Advanced Features](https://tomhea.github.io/farray/Advanced-Features.html) - iterator, direct-functions, smaller-blocks, templates\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomhea%2Ffarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomhea%2Ffarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomhea%2Ffarray/lists"}