Xan, the CSV Magician
github.com1 pointsby nicopappl0 comments
struct JaggedArray<T> {
offsets: Vec<u32>,
data: Vec<T>,
}
// impl JaggedArray<T>
fn add_row(&mut self, row: Vec<T>) {
self.data.extend(row);
self.offsets.push(self.len());
}
fn get_row(&self, row: usize) -> &[T] {
let start = self.offsets[row] as usize;
let end = self.offsets[row + 1] as usize;
&self.data[start..end]
}
Now this could be improved to reduce allocations, but it's fine as an illustration. fn get_row(&self, row: usize) -> &[T] {
let start = if row == 0 { 0 } else { self.offsets[row - 1] as usize };
let end = self.offsets[row] as usize;
&self.data[start..end]
}
Jagged arrays are super useful as lists of list, some better perf characteristics than the naive Illife Vector. I've used them extensively lately. It's also extra fun when you combine them with a bitset.
Being better at debugging doesn't necessarily makes you better at writing less complex, more approachable code. Though debugging should teach you which patterns cause bugs or impede debugging.
And what do you do once you are so skilled your software doesn't have bugs? :P
Regarding self improvement, Aaron Swartz put it better here: https://web.archive.org/web/20240928215405/http://www.aarons... (tldr: do things you don't like)