columned 0.1.2

A single, contiguous, allocation for multiple arrays
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 9 items with examples
  • Size
  • Source code size: 19.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Andful/Columned
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Andful

Columned

Crates.io Docs.rs MIT licensed

A single, contiguous, allocation for multiple arrays, of type Column<T>. Meant to allocate multiple arrays, or so called Column<T> that live the same lifetimes. The lifetimes of a Column<T>, and its backing memory, is tied to a Columned. Therefore, the user must guarantee that Columned outlives any Column<T> which it allocated for. Column<T> originating from a single allocation may have different sizes.
This crate facilitates the implementation of columnar data structures.

Example

use columned::*;

fn main() {
    let _columned; // Ensure this outlives the other variables.

    let mut xs: Column<f64> = Default::default();
    let mut ys: Column<f64> = Default::default();
    let mut sums: Column<f64> = Default::default();

    _columned = unsafe {
        Columned::new([
            xs.alloc(10),
            ys.alloc(10),
            sums.alloc(10)
        ])
    };

    for (i, x) in xs.maybe_uninit().iter_mut().enumerate() {
        x.write(i as f64);
    }

    for (i, y) in ys.maybe_uninit().iter_mut().enumerate() {
        y.write(i as f64);
    }

    for sum in sums.maybe_uninit().iter_mut() {
        sum.write(0.0);
    }

    for ((sum,x),y) in sums.iter_mut().zip(xs.iter()).zip(ys.iter()) {
        *sum = x + y;
    }

    println!("{:?}", sums);
}

Working Principle

Columned manages a contiguous allocation of memory. Each Coulmn have a pointer to this contiguous allocation. The following figure illustrates the working principle.

       Columned
       +--------+--------+
       | 0x0123 |   ...  |
       +--------+--------+
        ptr
         |
         V
Heap   +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
       |           0.1 |           3.2 |     5 |     7 |    20 |     6 |
       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
         ^                               ^
         |                               |
        ptr      len                    ptr      len
       +--------+--------+             +--------+--------+
       | 0x0123 |      2 |             | 0x012b |      4 |
       +--------+--------+             +--------+--------+
       Column<f32>                     Column<u16>

This also means that the user has to ensure that Columned outlives the Columns that uses its managed memory.