Skip to content

Commit

Permalink
Remove unused features of Count
Browse files Browse the repository at this point in the history
  • Loading branch information
nessex committed Jan 30, 2024
1 parent 165ddbd commit efecead
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 66 deletions.
69 changes: 4 additions & 65 deletions src/counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Counter {
return;
} else if bucket.len() == 1 {
let b = bucket[0].get_level(level) as usize;
counts.inc(b);
counts[b] += 1;

meta.first = b as u8;
meta.last = b as u8;
Expand All @@ -210,7 +210,7 @@ impl Counter {
// First, count directly into the output buffer until we find a value that is out of order.
for (i, item) in bucket.iter().enumerate() {
let b = item.get_level(level) as usize;
counts.inc(b);
counts[b] += 1;

if b < prev {
continue_from = i + 1;
Expand Down Expand Up @@ -245,12 +245,12 @@ impl Counter {

rem.iter().for_each(|v| {
let b = v.get_level(level) as usize;
counts.inc(b);
counts[b] += 1;
});

for i in 0..256 {
let agg = self.0[i * 4] + self.0[1 + i * 4] + self.0[2 + i * 4] + self.0[3 + i * 4];
counts.add(i, agg);
counts[i] += agg;
}

meta.first = first;
Expand All @@ -259,45 +259,12 @@ impl Counter {
}
}

pub struct CountIter<'a>(&'a Counts, usize);

pub struct CountIterEnumerable<'a>(&'a mut CountIter<'a>);

impl<'a> CountIter<'a> {
#[inline(always)]
pub fn enumerate(&'a mut self) -> CountIterEnumerable<'a> {
CountIterEnumerable(self)
}
}

impl Counts {
#[inline(always)]
pub fn clear(&mut self) {
self.0.iter_mut().for_each(|x| *x = 0);
}

#[inline(always)]
pub fn get_count(self, radix: usize) -> usize {
debug_assert!(radix < 256);
unsafe { *self.0.get_unchecked(radix) }
}

#[inline(always)]
pub fn inc(&mut self, radix: usize) {
debug_assert!(radix < 256);
unsafe {
*self.0.get_unchecked_mut(radix) += 1;
}
}

#[inline(always)]
pub fn add(&mut self, radix: usize, count: usize) {
debug_assert!(radix < 256);
unsafe {
*self.0.get_unchecked_mut(radix) += count;
}
}

#[inline(always)]
pub fn new() -> Self {
Self::default()
Expand All @@ -309,34 +276,6 @@ impl Counts {
}
}

impl Iterator for CountIter<'_> {
type Item = usize;

#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
if self.1 == 256 {
return None;
}

let out = self.0[self.1];
self.1 += 1;

Some(out)
}

#[inline(always)]
fn size_hint(&self) -> (usize, Option<usize>) {
(256 - self.1, Some(256 - self.1))
}
}

impl ExactSizeIterator for CountIter<'_> {
#[inline(always)]
fn len(&self) -> usize {
256 - self.1
}
}

impl IntoIterator for Counts {
type Item = usize;
type IntoIter = core::array::IntoIter<usize, 256>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sort_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn aggregate_tile_counts(cm: &CountManager, tile_counts: &[Counts]) -> Rc<Re

for tile in tile_counts.iter() {
for i in 0..256usize {
counts.add(i, tile[i]);
counts[i] += tile[i];
}
}

Expand Down

0 comments on commit efecead

Please sign in to comment.