mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 08:57:26 +02:00
Minor fix
This commit is contained in:
parent
2dd2bb86d9
commit
d1d44d1d81
1 changed files with 15 additions and 6 deletions
|
@ -19,17 +19,17 @@ fn xor_with<const L: usize>(x: &mut [u8; L], y: &[u8; L]) {
|
||||||
fn xor_with<const L: usize>(x: &mut [u8; L], y: &[u8; L]) {
|
fn xor_with<const L: usize>(x: &mut [u8; L], y: &[u8; L]) {
|
||||||
if L >= 16 {
|
if L >= 16 {
|
||||||
for i in 0..(L / 16) {
|
for i in 0..(L / 16) {
|
||||||
unsafe { *x.as_mut_ptr().cast::<u128>().add(i) ^= *y.as_ptr().cast::<u128>() };
|
unsafe { *x.as_mut_ptr().cast::<u128>().add(i) ^= *y.as_ptr().cast::<u128>().add(i) };
|
||||||
}
|
}
|
||||||
for i in (L - (L % 16))..L {
|
for i in (L - (L % 16))..L {
|
||||||
unsafe { *x.as_mut_ptr().cast::<u8>().add(i) ^= *y.as_ptr().cast::<u8>() };
|
unsafe { *x.as_mut_ptr().add(i) ^= *y.as_ptr().add(i) };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for i in 0..(L / 8) {
|
for i in 0..(L / 8) {
|
||||||
unsafe { *x.as_mut_ptr().cast::<u64>().add(i) ^= *y.as_ptr().cast::<u64>() };
|
unsafe { *x.as_mut_ptr().cast::<u64>().add(i) ^= *y.as_ptr().cast::<u64>().add(i) };
|
||||||
}
|
}
|
||||||
for i in (L - (L % 8))..L {
|
for i in (L - (L % 8))..L {
|
||||||
unsafe { *x.as_mut_ptr().cast::<u8>().add(i) ^= *y.as_ptr().cast::<u8>() };
|
unsafe { *x.as_mut_ptr().add(i) ^= *y.as_ptr().add(i) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,9 +210,9 @@ impl<const BUCKETS: usize, const ITEM_BYTES: usize, const HASHES: usize> IBLT<BU
|
||||||
let check_hash2 = self.check_hash[i2] ^ check_hash;
|
let check_hash2 = self.check_hash[i2] ^ check_hash;
|
||||||
let count2 = self.count[i2].wrapping_sub(count);
|
let count2 = self.count[i2].wrapping_sub(count);
|
||||||
let key2 = &mut self.key[i2];
|
let key2 = &mut self.key[i2];
|
||||||
xor_with(key2, &key);
|
|
||||||
self.check_hash[i2] = check_hash2;
|
self.check_hash[i2] = check_hash2;
|
||||||
self.count[i2] = count2;
|
self.count[i2] = count2;
|
||||||
|
xor_with(key2, &key);
|
||||||
if (count2 == 1 || count2 == -1) && check_hash2 == crc32fast::hash(key2) {
|
if (count2 == 1 || count2 == -1) && check_hash2 == crc32fast::hash(key2) {
|
||||||
if queue.len() > BUCKETS {
|
if queue.len() > BUCKETS {
|
||||||
// sanity check, should be impossible
|
// sanity check, should be impossible
|
||||||
|
@ -226,10 +226,19 @@ impl<const BUCKETS: usize, const ITEM_BYTES: usize, const HASHES: usize> IBLT<BU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.count.iter().all(|x| *x == 0) || self.check_hash.iter().all(|x| *x == 0)
|
self.check_hash.iter().all(|x| *x == 0) && self.count.iter().all(|x| *x == 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<const BUCKETS: usize, const ITEM_BYTES: usize, const HASHES: usize> PartialEq for IBLT<BUCKETS, ITEM_BYTES, HASHES> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.as_bytes().eq(other.as_bytes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const BUCKETS: usize, const ITEM_BYTES: usize, const HASHES: usize> Eq for IBLT<BUCKETS, ITEM_BYTES, HASHES> {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue