mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Run rustfmt on selectors, servo_arc, and style.
This was generated with: ./mach cargo fmt --package selectors && ./mach cargo fmt --package servo_arc && ./mach cargo fmt --package style Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
parent
f7ae1a37e3
commit
c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions
|
@ -72,11 +72,17 @@ pub type NonCountingBloomFilter = CountingBloomFilter<BloomStorageBool>;
|
|||
/// positive rate for N == 100 and to quite bad false positive
|
||||
/// rates for larger N.
|
||||
#[derive(Clone)]
|
||||
pub struct CountingBloomFilter<S> where S: BloomStorage {
|
||||
pub struct CountingBloomFilter<S>
|
||||
where
|
||||
S: BloomStorage,
|
||||
{
|
||||
storage: S,
|
||||
}
|
||||
|
||||
impl<S> CountingBloomFilter<S> where S: BloomStorage {
|
||||
impl<S> CountingBloomFilter<S>
|
||||
where
|
||||
S: BloomStorage,
|
||||
{
|
||||
/// Creates a new bloom filter.
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
|
@ -128,8 +134,7 @@ impl<S> CountingBloomFilter<S> where S: BloomStorage {
|
|||
|
||||
#[inline]
|
||||
pub fn might_contain_hash(&self, hash: u32) -> bool {
|
||||
!self.storage.first_slot_is_empty(hash) &&
|
||||
!self.storage.second_slot_is_empty(hash)
|
||||
!self.storage.first_slot_is_empty(hash) && !self.storage.second_slot_is_empty(hash)
|
||||
}
|
||||
|
||||
/// Check whether the filter might contain an item. This can
|
||||
|
@ -142,7 +147,10 @@ impl<S> CountingBloomFilter<S> where S: BloomStorage {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Debug for CountingBloomFilter<S> where S: BloomStorage {
|
||||
impl<S> Debug for CountingBloomFilter<S>
|
||||
where
|
||||
S: BloomStorage,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut slots_used = 0;
|
||||
for i in 0..ARRAY_SIZE {
|
||||
|
@ -154,7 +162,7 @@ impl<S> Debug for CountingBloomFilter<S> where S: BloomStorage {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait BloomStorage : Clone + Default {
|
||||
pub trait BloomStorage: Clone + Default {
|
||||
fn slot_is_empty(&self, index: usize) -> bool;
|
||||
fn adjust_slot(&mut self, index: usize, increment: bool);
|
||||
fn is_zeroed(&self) -> bool;
|
||||
|
@ -199,7 +207,8 @@ impl BloomStorage for BloomStorageU8 {
|
|||
#[inline]
|
||||
fn adjust_slot(&mut self, index: usize, increment: bool) {
|
||||
let slot = &mut self.counters[index];
|
||||
if *slot != 0xff { // full
|
||||
if *slot != 0xff {
|
||||
// full
|
||||
if increment {
|
||||
*slot += 1;
|
||||
} else {
|
||||
|
@ -249,8 +258,10 @@ impl BloomStorage for BloomStorageBool {
|
|||
// Since we have only one bit for storage, decrementing it
|
||||
// should never do anything. Assert against an accidental
|
||||
// decrementing of a bit that was never set.
|
||||
assert!(increment || (*byte & bit) != 0,
|
||||
"should not decrement if slot is already false");
|
||||
assert!(
|
||||
increment || (*byte & bit) != 0,
|
||||
"should not decrement if slot is already false"
|
||||
);
|
||||
|
||||
if increment {
|
||||
*byte |= bit;
|
||||
|
@ -314,34 +325,33 @@ fn create_and_insert_some_stuff() {
|
|||
transmute::<[u8; ARRAY_SIZE % 8], [u8; 0]>([]);
|
||||
}
|
||||
|
||||
for i in 0_usize .. 1000 {
|
||||
for i in 0_usize..1000 {
|
||||
bf.insert(&i);
|
||||
}
|
||||
|
||||
for i in 0_usize .. 1000 {
|
||||
for i in 0_usize..1000 {
|
||||
assert!(bf.might_contain(&i));
|
||||
}
|
||||
|
||||
let false_positives =
|
||||
(1001_usize .. 2000).filter(|i| bf.might_contain(i)).count();
|
||||
let false_positives = (1001_usize..2000).filter(|i| bf.might_contain(i)).count();
|
||||
|
||||
assert!(false_positives < 150, "{} is not < 150", false_positives); // 15%.
|
||||
|
||||
for i in 0_usize .. 100 {
|
||||
for i in 0_usize..100 {
|
||||
bf.remove(&i);
|
||||
}
|
||||
|
||||
for i in 100_usize .. 1000 {
|
||||
for i in 100_usize..1000 {
|
||||
assert!(bf.might_contain(&i));
|
||||
}
|
||||
|
||||
let false_positives = (0_usize .. 100).filter(|i| bf.might_contain(i)).count();
|
||||
let false_positives = (0_usize..100).filter(|i| bf.might_contain(i)).count();
|
||||
|
||||
assert!(false_positives < 20, "{} is not < 20", false_positives); // 20%.
|
||||
|
||||
bf.clear();
|
||||
|
||||
for i in 0_usize .. 2000 {
|
||||
for i in 0_usize..2000 {
|
||||
assert!(!bf.might_contain(&i));
|
||||
}
|
||||
}
|
||||
|
@ -376,13 +386,13 @@ mod bench {
|
|||
let mut gen1 = HashGenerator::default();
|
||||
let mut gen2 = HashGenerator::default();
|
||||
let mut bf = BloomFilter::new();
|
||||
for _ in 0_usize .. 1000 {
|
||||
for _ in 0_usize..1000 {
|
||||
bf.insert_hash(gen1.next());
|
||||
}
|
||||
for _ in 0_usize .. 100 {
|
||||
for _ in 0_usize..100 {
|
||||
bf.remove_hash(gen2.next());
|
||||
}
|
||||
for _ in 100_usize .. 200 {
|
||||
for _ in 100_usize..200 {
|
||||
test::black_box(bf.might_contain_hash(gen2.next()));
|
||||
}
|
||||
});
|
||||
|
@ -392,8 +402,10 @@ mod bench {
|
|||
fn might_contain_10(b: &mut test::Bencher) {
|
||||
let bf = BloomFilter::new();
|
||||
let mut gen = HashGenerator::default();
|
||||
b.iter(|| for _ in 0..10 {
|
||||
test::black_box(bf.might_contain_hash(gen.next()));
|
||||
b.iter(|| {
|
||||
for _ in 0..10 {
|
||||
test::black_box(bf.might_contain_hash(gen.next()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -407,8 +419,10 @@ mod bench {
|
|||
fn insert_10(b: &mut test::Bencher) {
|
||||
let mut bf = BloomFilter::new();
|
||||
let mut gen = HashGenerator::default();
|
||||
b.iter(|| for _ in 0..10 {
|
||||
test::black_box(bf.insert_hash(gen.next()));
|
||||
b.iter(|| {
|
||||
for _ in 0..10 {
|
||||
test::black_box(bf.insert_hash(gen.next()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -417,8 +431,10 @@ mod bench {
|
|||
let mut bf = BloomFilter::new();
|
||||
let mut gen = HashGenerator::default();
|
||||
// Note: this will underflow, and that's ok.
|
||||
b.iter(|| for _ in 0..10 {
|
||||
bf.remove_hash(gen.next())
|
||||
b.iter(|| {
|
||||
for _ in 0..10 {
|
||||
bf.remove_hash(gen.next())
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue