{"id":20145856,"url":"https://github.com/usagi/dimension_shiftable_buffer","last_synced_at":"2025-08-22T12:05:40.924Z","repository":{"id":57619350,"uuid":"288738456","full_name":"usagi/dimension_shiftable_buffer","owner":"usagi","description":"The `DimensionShiftableBuffer` by this crate presents a dimension shiftable buffer feature.","archived":false,"fork":false,"pushed_at":"2020-08-19T18:07:22.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-21T15:38:25.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/usagi.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":"2020-08-19T13:24:34.000Z","updated_at":"2020-08-19T18:07:24.000Z","dependencies_parsed_at":"2022-09-16T19:01:57.212Z","dependency_job_id":null,"html_url":"https://github.com/usagi/dimension_shiftable_buffer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/usagi/dimension_shiftable_buffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fdimension_shiftable_buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fdimension_shiftable_buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fdimension_shiftable_buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fdimension_shiftable_buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usagi","download_url":"https://codeload.github.com/usagi/dimension_shiftable_buffer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi%2Fdimension_shiftable_buffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271635425,"owners_count":24794140,"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-08-22T02:00:08.480Z","response_time":65,"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":[],"created_at":"2024-11-13T22:18:27.191Z","updated_at":"2025-08-22T12:05:40.890Z","avatar_url":"https://github.com/usagi.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![github]](https://github.com/usagi/dimension_shiftable_buffer)\u0026ensp;[![crates-io]](https://crates.io/crates/dimension_shiftable_buffer)\u0026ensp;[![docs-rs]](https://docs.rs/dimension_shiftable_buffer)\u003cbr\u003e\n[![Build Status](https://travis-ci.org/usagi/dimension_shiftable_buffer.svg?branch=master)](https://travis-ci.org/usagi/dimension_shiftable_buffer)\n\n[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\n[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge\u0026labelColor=555555\u0026logo=rust\n[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logoColor=white\u0026logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K\n\n# Dimension shiftable buffer\n\nThe `DimensionShiftableBuffer` by this crate presents a dimension shiftable buffer feature.\n\n## What's the \"dimension shiftable buffer\"?\n\n- First, a dimension \"un-shiftable\" buffer is a common buffer types such as:\n  - `[T;3]` = One datum, 3-fixed-dimension, buffer is allocated a single heap, elements placed on a sequential memory addresses.\n  - `[[T;3]]` = 0..* data, 3-fixed-dimension, buffer is allocated a single heap, elements placed on a sequential memory addresses.\n  - `Vec\u003cT\u003e` = 0..* data, 1-fiexed-dimension, buffer is allocated a single heap, elements placed on a sequential memory addresses.\n  - `Vec\u003c[T;3]\u003e` = 0..* data, 3-fixed-dimension, buffer is allocated a single heap, elements placed on a sequential memory addresses.\n  - `Vec\u003cVec\u003cT\u003e\u003e` = 0..* data, 1..*-any-dimension, buffer is allocated a multiple heap, elements placed on a dispersed memory addresses.\n- Then, a dimension \"shiftable\" buffer is:\n  - `DimensionShiftableBuffer\u003cT\u003e` = 0..* data, N-shiftable-dimension, buffer is allocated a single heap, elements places on a sequential memory addresses.\n    - Has one buffer heap.\n    - Can access as N=1..* dimension view such as like a `[\u0026[T;3]]`, `[\u0026mut [T;3]]`, `[\u0026[T;127]]`.\n    - With only safe implementation.\n\n## Example\n\n```toml\n[dependencies]\ndimension_shiftable_buffer = \"*\"\n```\n\n### Example-1\n\nA simple usages.\n\n```rust\n// make a 2d-empty DimensionShiftableBuffer\nlet mut dsb = DimensionShiftableBuffer::\u003cu8\u003e::new(vec![], 2).unwrap();\n// push a 2d-datum\ndsb.push(\u0026[0u8, 1]).unwrap();\n// push a 2d-datum\ndsb.push(\u0026[2u8, 3]).unwrap();\n// append a 2d-datum sequence\ndsb.append(\u0026[4u8, 5, 6, 7, 8, 9, 10, 11]).unwrap();\nfor index in 0..dsb.len().unwrap()\n{\n // get a 2d slice\n assert_eq!(dsb.get(index).unwrap(), \u0026[index as u8 * 2, index as u8 * 2 + 1]);\n}\n// shift dimension to 3 from 2\ndsb.shift_dimension(3).unwrap();\n// push a 3d-datum\ndsb.push(\u0026[12u8, 13, 14]).unwrap();\n// get a 3d-datum\nassert_eq!(dsb.get(0).unwrap(), \u0026[0u8, 1, 2]);\nassert_eq!(dsb.get(1).unwrap(), \u0026[3u8, 4, 5]);\nassert_eq!(dsb.get(2).unwrap(), \u0026[6u8, 7, 8]);\nassert_eq!(dsb.get(3).unwrap(), \u0026[9u8, 10, 11]);\nassert_eq!(dsb.get(4).unwrap(), \u0026[12u8, 13, 14]);\n// get a linear slice\nlet linear_slice = dsb.as_slice();\nassert_eq!(linear_slice, \u0026[0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);\n```\n\n### Example-2\n\nWith an error handling.\n\n```rust\nuse dimension_shiftable_buffer::DimensionShiftableBuffer\n\n // Index of 1D =\u003e           0      |1   |2   |3   |4   |5   |6   |7   |8   |\n // Index of 2D =\u003e           0,0     0,1 |1,0  1,1 |2,0  2,1 |3,0  3,1 |4,0  4,1 |\n // Index of 3D =\u003e           0,0     0,1  0,2 |1,0  1,1  1,2 |2,0  2,1  2,2 |\n // Index of 7D =\u003e           0,0     0,1  0,2  0,3  0,4  0,5  0,6 |1,0  1,1  1,2  1,3  1,4  1,5  1,6 |\n let entity = vec![1.1f32, 1.2, 1.3, 2.1, 2.2, 2.3, 3.1, 3.2, 3.3];\n let dimension = 1;\n\n let mut dsb = DimensionShiftableBuffer::\u003cf32\u003e::new(entity, dimension).unwrap();\n\n let d1_i3 = dsb.get(3).unwrap();\n assert_eq!(d1_i3, [2.1f32]);\n\n dsb.shift_dimension(3).unwrap();\n\n let d3_i2 = dsb.get(2).unwrap();\n assert_eq!(d3_i2, [3.1f32, 3.2, 3.3]);\n\n match dsb.shift_dimension(2)\n {\n  Ok(_) =\u003e panic!(\"Detect an unexpected false-ok.\"),\n  Err(_) =\u003e eprintln!(\"Expected err.\")\n }\n\n dsb.shift_dimension_truncate(2).unwrap();\n\n let d2_i1 = dsb.get(1).unwrap();\n assert_eq!(d2_i1, [1.3f32, 2.1]);\n\n dsb.shift_dimension_padding(7, std::f32::NAN).unwrap();\n let d7_i1 = dsb.get(1).unwrap();\n assert_eq!(\n  // rounding, just easily\n  format!(\"{:?}\", d7_i1),\n  format!(\"{:?}\", \u0026[\n   // [0] of 7-d\n   3.2f32,\n   // [1] of 7-d, truncated at .shift_dimension.truncate(2) -\u003e padding at .shift_dimension_padding(7)\n   std::f32::NAN,\n   // [2] of 7-d, padding at .shift_dimension_padding(7)\n   std::f32::NAN,\n   std::f32::NAN,\n   std::f32::NAN,\n   std::f32::NAN,\n   std::f32::NAN\n  ])\n )\n```\n\n### Example-3\n\nAdditional feature=\"csv\" (default).; CSV=Character-Separated-Values, also known as DSV or TSV.\n\n```\nlet delimiter = \" \";\nlet source = \"0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0\";\nlet dimension = 3;\n// construct\nlet mut dsb = DimensionShiftableBuffer::\u003cf32\u003e::from_csv(source, dimension, delimiter).unwrap();\n// modify-1\ndsb.for_each(|v| *v += 0.1);\n// modify-2\nfor n in 0..dsb.len().unwrap()\n{\n for v in dsb.get_mut(n).unwrap()\n {\n  *v *= *v;\n }\n}\n// show\neprintln!(\"{:?}\", dsb);\n// enumerate\nfor i in 0..18\n// maybe, 0..5 will ok, 6..18 will err\n{\n match dsb.get(i)\n {\n  Ok(dimensional_elements) =\u003e\n  {\n   for (i_sub, actual) in dimensional_elements.iter().enumerate()\n   {\n    let i_flatten = i * dimension as usize + i_sub;\n    let expected = (i_flatten as f32 + 0.1) * (i_flatten as f32 + 0.1);\n    assert_eq!(actual, \u0026expected);\n   }\n  },\n  Err(e) =\u003e\n  {\n   match e\n   {\n    DimensionShiftableBufferError::OutOfRange {\n     limit: _,\n     requested: _\n    } =\u003e (),\n    _ =\u003e panic!(\"unexpected err: {:?}\", e)\n   }\n  },\n }\n}\nprintln!(\"\u003c\u003cprint CSV, as a sequential slice\u003e\u003e\\n{}\", dsb.to_csv(\", \"));\nprintln!(\n \"\u003c\u003cprint CSV, as a dimmensional slices\u003e\u003e\\n{}\",\n dsb.to_csv_dimensional(\", \", \"\\n\").unwrap()\n);\n```\n\n```sh\n\u003c\u003cprint CSV, as a sequential slice\u003e\u003e\n0.010000001, 1.21, 4.4099994, 9.61, 16.81, 26.009998, 37.21, 50.41, 65.61001, 82.810005, 102.01001, 123.21001, 146.41, 171.61002, 198.81001, 228.01001, 259.21002, 292.41\n\u003c\u003cprint CSV, as a dimmensional slices\u003e\u003e\n0.010000001, 1.21, 4.4099994\n9.61, 16.81, 26.009998\n37.21, 50.41, 65.61001\n82.810005, 102.01001, 123.21001\n146.41, 171.61002, 198.81001\n228.01001, 259.21002, 292.41\n```\n\n## License\n\n- [MIT](LICENSE.md)\n\n## Author\n\n- [USAGI.NETWORK / Usagi Ito](https://github.com/usagi/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Fdimension_shiftable_buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusagi%2Fdimension_shiftable_buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi%2Fdimension_shiftable_buffer/lists"}