30 lines
497 B
Rust
30 lines
497 B
Rust
use std::{collections::HashMap, hash::Hash};
|
|
|
|
pub struct Grid<Dim, T> {
|
|
data: HashMap<Dim, T>,
|
|
}
|
|
|
|
impl<Dim, T> Grid<Dim, T>
|
|
where
|
|
Dim: Eq + PartialEq + Hash,
|
|
{
|
|
pub fn new() -> Self {
|
|
Self {
|
|
data: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
pub fn get(&self, idx: impl Into<Dim>) -> Option<&T> {
|
|
self.data.get(&idx.into())
|
|
}
|
|
}
|
|
|
|
impl<Dim, T> Default for Grid<Dim, T>
|
|
where
|
|
Dim: Eq + PartialEq + Hash,
|
|
{
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|