Skip to content

Commit

Permalink
wip: sparse bool meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Nov 25, 2024
1 parent f4cbcce commit 95748ac
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions src/expr/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::ExprRef;
use baa::Word;
use rustc_hash::FxHashMap;
use rustc_hash::{FxHashMap, FxHashSet};
use std::fmt::Debug;
use std::ops::Index;

Expand Down Expand Up @@ -188,7 +188,7 @@ impl ExprMetaData<bool> for DenseExprMetaDataBool {
where
bool: 'a,
{
ExprMetaBoolIter {
DenseExprMetaBoolIter {
inner: self.inner.iter(),
value: 0,
index: 0,
Expand All @@ -211,13 +211,13 @@ impl ExprMetaData<bool> for DenseExprMetaDataBool {
}
}

struct ExprMetaBoolIter<'a> {
struct DenseExprMetaBoolIter<'a> {
inner: std::slice::Iter<'a, u64>,
value: u64,
index: usize,
}

impl<'a> Iterator for ExprMetaBoolIter<'a> {
impl<'a> Iterator for DenseExprMetaBoolIter<'a> {
type Item = (ExprRef, &'a bool);

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -243,6 +243,64 @@ impl<'a> Iterator for ExprMetaBoolIter<'a> {
const TRU: bool = true;
const FALS: bool = false;

/// A sparse hash map to store boolean meta-data related to each expression
#[derive(Debug, Default, Clone)]
pub struct SparseExprMetaDataBool {
inner: FxHashSet<ExprRef>,
max_ref: usize,
}

impl Index<ExprRef> for SparseExprMetaDataBool {
type Output = bool;

#[inline]
fn index(&self, index: ExprRef) -> &Self::Output {
if self.inner.contains(&index) {
&TRU
} else {
&FALS
}
}
}

impl ExprMetaData<bool> for SparseExprMetaDataBool {
#[inline]
fn iter<'a>(&'a self) -> impl Iterator<Item = (ExprRef, &'a bool)>
where
bool: 'a,
{
todo!()
// SparseExprMetaBoolIter {
// index: usize,
// max_ref: self.max_ref,
// }
}

#[inline]
fn insert(&mut self, e: ExprRef, data: bool) {
self.max_ref = std::cmp::max(e.index(), self.max_ref);
if data {
self.inner.insert(e);
} else {
self.inner.remove(&e);
}
}
}

// struct SparseExprMetaBoolIter<'a> {
// inner:
// max_ref: usize,
// index: usize,
// }

// impl<'a> Iterator for SparseExprMetaBoolIter<'a> {
// type Item = (ExprRef, &'a bool);
//
// fn next(&mut self) -> Option<Self::Item> {
// todo!()
// }
// }

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 95748ac

Please sign in to comment.