binius_core/piop/
util.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright 2024-2025 Irreducible Inc.

pub struct ResizeableIndex<T> {
	entries: Vec<T>,
}

impl<T: Default> ResizeableIndex<T> {
	pub const fn new() -> Self {
		Self {
			entries: Vec::new(),
		}
	}

	pub fn get_mut(&mut self, id: usize) -> &mut T {
		if id >= self.entries.len() {
			self.entries.resize_with(id + 1, T::default);
		}
		&mut self.entries[id]
	}

	pub fn into_vec(self) -> Vec<T> {
		self.entries
	}
}