1 unstable release
0.1.0 | Jun 14, 2024 |
---|
#1527 in Data structures
14KB
215 lines
Table of Contents
About The Project
Allow to create Table like structure represented by a structure of Arrays maintaining multiple arrays of different types while maintaining the same size for all the arrays and a shared index for each attribute created throughout its lifetime.
Provide a Table struct that allows to store rows of data composed of different types. This structure can be represented as a Structure of arrays and is built has an HashMap where keys are column identifiers and values are Column. Each Column is a contiguous array and every row component can be accessed with the same index on each Column.
Built With
- Nohash to create hashmap without hashing algorithm (keys are u32) - https://github.com/tetcoin/nohash
- Based on bevy BlobVec implementation - https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs
Getting Started
This is an example of how you use this crate to to create a table struct with a simple columns.
Installation
Add dependency to you cargo.toml
[dependencies]
type-erased-table = "0.1.0"
Usage
After creating a table just add a column and start filling it with un-typed data.
let mut table = Table::new(1);
let value: u32 = 2;
// Get Layout from concrete type
let layout = Layout::for_value(&value);
// Create column with u32 identifier
let column_info = ColumnInfo::new(1, layout);
table.add_column(column_info);
let column = table.get_column_mut(1).unwrap();
// Push data into row of column by passing pointer as *const u8
unsafe { column.push(ptr::addr_of!(value) as *const u8) }
// Read value of row 0
let row_ptr = unsafe { column.get(0) };
let row_value: u32 = unsafe { (*row_ptr).into() };
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License.
Contact
Project Link: https://github.com/ValentinRio/type-erased-table
Dependencies
~15KB