{"id":29717491,"url":"https://github.com/tauseefk/rasengan","last_synced_at":"2025-10-03T12:59:58.988Z","repository":{"id":202953056,"uuid":"708239148","full_name":"tauseefk/rasengan","owner":"tauseefk","description":"Minimal circular buffer implementation.","archived":false,"fork":false,"pushed_at":"2024-12-14T20:32:22.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-13T09:51:43.663Z","etag":null,"topics":["circular-buffer","data-structures","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/tauseefk.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}},"created_at":"2023-10-22T00:09:43.000Z","updated_at":"2024-12-14T20:32:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec8ca039-8b76-4cfc-967c-f33e30feb54c","html_url":"https://github.com/tauseefk/rasengan","commit_stats":null,"previous_names":["tauseefk/rasengan"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tauseefk/rasengan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauseefk%2Frasengan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauseefk%2Frasengan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauseefk%2Frasengan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauseefk%2Frasengan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tauseefk","download_url":"https://codeload.github.com/tauseefk/rasengan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauseefk%2Frasengan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278165690,"owners_count":25940958,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["circular-buffer","data-structures","rust"],"created_at":"2025-07-24T07:43:16.295Z","updated_at":"2025-10-03T12:59:58.981Z","avatar_url":"https://github.com/tauseefk.png","language":"Rust","readme":"# Rasengan\n\nMinimal circular buffer implementation.\nAllows overwriting data once the buffer is full. Only allows reading data once.\n\n## Write with wrap-around\nIn this approach `W` and `R` are incremented indefinitely (until overflow), capacity is enforced by `r = R % capacity` and `w = W % capacity`.\n```\n                                                                 \n           W       R                                             \n           │       │                                             \n       ╔═══▼═══╦═══▼═══╦═══════╦═══════╦───────┬───────┐         \n       ║       ║       ║       ║       ║       │       │▐▌       \n       ║       ║       ║       ║       ║       │       │▐▌       \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┘▐▌       \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▘       \n           └─── Capacity = 4 ──────┘                             \n                                                                 \n       W \u003c R // buffer has no unread values                      \n       read() -\u003e panic(\"Nothing to read here\")                   \n                                                                 \n           W       R                                             \n           │       │                                             \n       ╔═══▼═══╦═══▼═══╦═══════╦═══════╦───────┬───────┐         \n       ║       ║       ║       ║       ║       │       │▐▌       \n       ║       ║   5   ║       ║       ║       │       │▐▌       \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┘▐▌       \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▘       \n           └───────────────────────┘                             \n                                                                 \n       inc(W); write(5); // increment W before writing           \n                                                                 \n           w       R                       W                     \n           │       │                       │                     \n       ╔═══▼═══╦═══▼═══╦═══════╦═══════╦───▼───┬───────┐         \n       ║       ║       ║       ║       ║       │       │▐▌       \n       ║   8   ║   5   ║   2   ║   4   ║       │       │▐▌       \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┘▐▌       \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▘       \n           └───────────────────────┘                             \n                                                                 \n       inc(W); write(2); inc(W); write(4); inc(W); write(8);     \n       w = W % capacity // write with wrap-around                \n                                                                 \n                                                                 \n```\n\n---\n## Fork in the road\nDepending on the sequence of operations there are two alternatives:\n\n### Read with wrap-around\nIn this case the reader resumes, so no unread values were overwritten.\n\n```\n                                                                                    \n                                                                 \n           w       r                       W       R             \n           │       │                       │       │             \n       ╔═══▼═══╦═══▼═══╦═══════╦═══════╦───▼───┬───▼───┐         \n       ║       ║       ║       ║       ║       │       │▐▌       \n       ║   8   ║   5   ║   2   ║   4   ║       │       │▐▌       \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┘▐▌       \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀        \n           └───────────────────────┘                             \n                                                                 \n       read() -\u003e 2; inc(R);                                      \n       read() -\u003e 4; inc(R);                                      \n       read() -\u003e 8; inc(R);                                      \n       r = R % capacity // read with wrap-around                 \n       w \u003c R // buffer has no unread values                      \n       read() -\u003e panic(\"Nothing to read here.\")                  \n\n                                                                 \n```\n\n### Write with overwrites\nIn this case the reader is still busy and the writer overwrites unread values. The read pointer is then moved to the least recent values in the buffer.\n\n```\n                                                                          \n                                                           ╷              \n                             ├───────╴capacity - 1╶────────┤              \n                         w  R,r                            W              \n                         │   │                             │              \n       ╔═══════╦═══════╦═▼═══▼═╦═══════╦───────┬───────┬───▼───┐          \n       ║       ║       ║       ║       ║       │       │       │▐▌        \n       ║   8   ║   7   ║  10   ║   4   ║       │       │       │▐▌        \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┴───────┘▐▌        \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀         \n           └───────────────────────┘                                      \n                                                                          \n       inc(W); write(7); inc(W); write(10);                               \n       W - R = capacity - 1                                               \n       // unread values at capacity,                                      \n       // next write overwrites unread values                             \n       inc(R) // move to least recent value in the buffer                 \n                                                                          \n                                                                          \n                                                                          \n                                                                          \n                           w      R,r                      W              \n                           │       │                       │              \n       ╔═══════╦═══════╦═══▼═══╦═══▼═══╦───────┬───────┬───▼───┐          \n       ║       ║       ║       ║       ║       │       │       │▐▌        \n       ║   8   ║   7   ║  10   ║   4   ║       │       │       │▐▌        \n       ╚═══▲═══╩═══════╩═══════╩═══╤═══╩───────┴───────┴───────┘▐▌        \n        ▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀│▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀         \n           └───────────────────────┘                                      \n                                                                          \n       FINAL CONFIGURATION                                                \n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftauseefk%2Frasengan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftauseefk%2Frasengan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftauseefk%2Frasengan/lists"}