Skip to content

Commit

Permalink
Merge pull request #41 from teymour-aldridge/no_coverage_feature_update
Browse files Browse the repository at this point in the history
No coverage feature update
  • Loading branch information
teymour-aldridge authored Oct 26, 2023
2 parents cd8ab38 + 3a5ad2e commit e7dadac
Show file tree
Hide file tree
Showing 101 changed files with 1,334 additions and 1,321 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]

resolver = "2"
members = [
"fuzzcheck_common",
"cargo-fuzzcheck",
Expand Down
56 changes: 28 additions & 28 deletions fuzzcheck/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const BITS: usize = 64;
type Block = u64;

#[inline(always)]
#[no_coverage]
#[coverage(off)]
fn div_rem(x: usize, d: usize) -> (usize, usize) {
(x / d, x % d)
}
Expand All @@ -53,7 +53,7 @@ pub struct FixedBitSet {

impl FixedBitSet {
/// Create a new empty **FixedBitSet**.
#[no_coverage]
#[coverage(off)]
pub const fn new() -> Self {
FixedBitSet {
data: Vec::new(),
Expand All @@ -63,7 +63,7 @@ impl FixedBitSet {

/// Create a new **FixedBitSet** with a specific number of bits,
/// all initially clear.
#[no_coverage]
#[coverage(off)]
pub fn with_capacity(bits: usize) -> Self {
let (mut blocks, rem) = div_rem(bits, BITS);
blocks += (rem > 0) as usize;
Expand All @@ -74,7 +74,7 @@ impl FixedBitSet {
}

/// Grow capacity to **bits**, all new bits initialized to zero
#[no_coverage]
#[coverage(off)]
pub fn grow(&mut self, bits: usize) {
if bits > self.length {
let (mut blocks, rem) = div_rem(bits, BITS);
Expand All @@ -86,14 +86,14 @@ impl FixedBitSet {

/// Return the length of the [`FixedBitSet`] in bits.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn len(&self) -> usize {
self.length
}

/// Return if the [`FixedBitSet`] is empty.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
Expand All @@ -105,7 +105,7 @@ impl FixedBitSet {
///
/// Note: Also available with index syntax: `bitset[bit]`.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn contains(&self, bit: usize) -> bool {
let (block, i) = div_rem(bit, BITS);
match self.data.get(block) {
Expand All @@ -116,7 +116,7 @@ impl FixedBitSet {

/// Clear all bits.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn clear(&mut self) {
for elt in &mut self.data {
*elt = 0
Expand All @@ -127,7 +127,7 @@ impl FixedBitSet {
///
/// **Panics** if **bit** is out of bounds.
#[inline(always)]
#[no_coverage]
#[coverage(off)]
pub fn insert(&mut self, bit: usize) {
assert!(
bit < self.length,
Expand All @@ -145,7 +145,7 @@ impl FixedBitSet {
///
/// **Panics** if **bit** is out of bounds.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn put(&mut self, bit: usize) -> bool {
assert!(
bit < self.length,
Expand All @@ -165,7 +165,7 @@ impl FixedBitSet {
///
/// ***Panics*** if **bit** is out of bounds
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn toggle(&mut self, bit: usize) {
assert!(
bit < self.length,
Expand All @@ -185,7 +185,7 @@ impl FixedBitSet {
///
/// **Panics** if the range extends past the end of the bitset.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn count_ones(&self) -> usize {
let mut sum = 0;
for block in &self.data {
Expand All @@ -198,7 +198,7 @@ impl FixedBitSet {
///
/// Iterator element is the index of the `1` bit, type `usize`.
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn ones(&self) -> Ones {
match self.as_slice().split_first() {
Some((&block, rem)) => Ones {
Expand All @@ -216,15 +216,15 @@ impl FixedBitSet {

/// View the bitset as a slice of `u64` blocks
#[inline]
#[no_coverage]
#[coverage(off)]
pub fn as_slice(&self) -> &[u64] {
&self.data
}

/// In-place union of two `FixedBitSet`s.
///
/// On calling this method, `self`'s capacity may be increased to match `other`'s.
#[no_coverage]
#[coverage(off)]
pub fn union_with(&mut self, other: &FixedBitSet) {
if other.len() >= self.len() {
self.grow(other.len());
Expand All @@ -237,7 +237,7 @@ impl FixedBitSet {
/// In-place intersection of two `FixedBitSet`s.
///
/// On calling this method, `self`'s capacity will remain the same as before.
#[no_coverage]
#[coverage(off)]
pub fn intersect_with(&mut self, other: &FixedBitSet) {
for (x, y) in self.data.iter_mut().zip(other.data.iter()) {
*x &= *y;
Expand All @@ -251,7 +251,7 @@ impl FixedBitSet {
/// In-place difference of two `FixedBitSet`s.
///
/// On calling this method, `self`'s capacity will remain the same as before.
#[no_coverage]
#[coverage(off)]
pub fn difference_with(&mut self, other: &FixedBitSet) {
for (x, y) in self.data.iter_mut().zip(other.data.iter()) {
*x &= !*y;
Expand All @@ -268,7 +268,7 @@ impl FixedBitSet {
/// In-place symmetric difference of two `FixedBitSet`s.
///
/// On calling this method, `self`'s capacity may be increased to match `other`'s.
#[no_coverage]
#[coverage(off)]
pub fn symmetric_difference_with(&mut self, other: &FixedBitSet) {
if other.len() >= self.len() {
self.grow(other.len());
Expand All @@ -292,7 +292,7 @@ impl<'a> Iterator for Ones<'a> {
type Item = usize; // the bit position of the '1'

#[inline]
#[no_coverage]
#[coverage(off)]
fn next(&mut self) -> Option<Self::Item> {
while self.bitset == 0 {
if self.remaining_blocks.is_empty() {
Expand All @@ -312,7 +312,7 @@ impl<'a> Iterator for Ones<'a> {

impl<'a> BitAnd for &'a FixedBitSet {
type Output = FixedBitSet;
#[no_coverage]
#[coverage(off)]
fn bitand(self, other: &FixedBitSet) -> FixedBitSet {
let (short, long) = {
if self.len() <= other.len() {
Expand All @@ -331,22 +331,22 @@ impl<'a> BitAnd for &'a FixedBitSet {
}

impl BitAndAssign for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitand_assign(&mut self, other: Self) {
self.intersect_with(&other);
}
}

impl BitAndAssign<&Self> for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitand_assign(&mut self, other: &Self) {
self.intersect_with(other);
}
}

impl<'a> BitOr for &'a FixedBitSet {
type Output = FixedBitSet;
#[no_coverage]
#[coverage(off)]
fn bitor(self, other: &FixedBitSet) -> FixedBitSet {
let (short, long) = {
if self.len() <= other.len() {
Expand All @@ -365,22 +365,22 @@ impl<'a> BitOr for &'a FixedBitSet {
}

impl BitOrAssign for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitor_assign(&mut self, other: Self) {
self.union_with(&other);
}
}

impl BitOrAssign<&Self> for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitor_assign(&mut self, other: &Self) {
self.union_with(other);
}
}

impl<'a> BitXor for &'a FixedBitSet {
type Output = FixedBitSet;
#[no_coverage]
#[coverage(off)]
fn bitxor(self, other: &FixedBitSet) -> FixedBitSet {
let (short, long) = {
if self.len() <= other.len() {
Expand All @@ -399,14 +399,14 @@ impl<'a> BitXor for &'a FixedBitSet {
}

impl BitXorAssign for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitxor_assign(&mut self, other: Self) {
self.symmetric_difference_with(&other);
}
}

impl BitXorAssign<&Self> for FixedBitSet {
#[no_coverage]
#[coverage(off)]
fn bitxor_assign(&mut self, other: &Self) {
self.symmetric_difference_with(other);
}
Expand Down
14 changes: 7 additions & 7 deletions fuzzcheck/src/bloom_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<T: ?Sized> BloomFilter<T> {
///
/// * 'size' - A usize that sets the size of the filter
/// * 'false_pos_rate' - The acceptable false positive rate
#[no_coverage]
#[coverage(off)]
pub fn new(size: usize, false_pos_rate: f64) -> Self {
let k = Self::optimal_k(false_pos_rate);
let m = Self::optimal_m(false_pos_rate, size);
Expand All @@ -76,7 +76,7 @@ impl<T: ?Sized> BloomFilter<T> {
/// where P is the probability of false positives
/// and n is the acceptable false postive rate
/// k = ( -( n * lnP ) / (ln2)^2 )
#[no_coverage]
#[coverage(off)]
fn optimal_m(false_pos_rate: f64, size: usize) -> usize {
((size as f64 * FALSE_POS_PROB * false_pos_rate.ln()) / LN_2_SQR).ceil() as usize
}
Expand All @@ -87,13 +87,13 @@ impl<T: ?Sized> BloomFilter<T> {
///
/// where P is the probability of false positives
/// k = ( - lnP / ln2 )
#[no_coverage]
#[coverage(off)]
fn optimal_k(false_pos_rate: f64) -> u64 {
(false_pos_rate.ln() * FALSE_POS_PROB / LN_2).ceil() as u64
}

/// Hash values T for Bloomfilter
#[no_coverage]
#[coverage(off)]
fn hash(&self, t: &T) -> (u64, u64)
where
T: Hash,
Expand All @@ -113,13 +113,13 @@ impl<T: ?Sized> BloomFilter<T> {
/// Prevent Overflow:
/// wrapping_add: wrapping add around at the boundary type
/// wrapping_mul: wrapping mult around at the boundary type
#[no_coverage]
#[coverage(off)]
fn find_index(&self, i: u64, hash1: u64, hash2: u64) -> usize {
hash1.wrapping_add((i).wrapping_mul(hash2)) as usize % self.m
}

/// Insert T into the BloomFilter index
#[no_coverage]
#[coverage(off)]
pub fn insert(&mut self, t: &T)
where
T: Hash,
Expand All @@ -133,7 +133,7 @@ impl<T: ?Sized> BloomFilter<T> {
}

/// Check if t of type T is in the BloomFilter index
#[no_coverage]
#[coverage(off)]
pub fn contains(&mut self, t: &T) -> bool
where
T: Hash,
Expand Down
Loading

0 comments on commit e7dadac

Please sign in to comment.