Fix bug in DupFilter that breaks serialize/deserialize
This commit is contained in:
parent
2d9febaf14
commit
794f80ab11
File diff suppressed because one or more lines are too long
|
@ -4,8 +4,7 @@
|
||||||
This implementation just keeps the table of seen ids in memory, but a
|
This implementation just keeps the table of seen ids in memory, but a
|
||||||
production one would of course use a disk-backed database. */
|
production one would of course use a disk-backed database. */
|
||||||
|
|
||||||
use std::cmp::Eq;
|
use std::collections::HashSet;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -14,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
||||||
/// seen ids. IdType will typically be Scalar.
|
/// seen ids. IdType will typically be Scalar.
|
||||||
#[derive(Default, Debug, Serialize, Deserialize)]
|
#[derive(Default, Debug, Serialize, Deserialize)]
|
||||||
pub struct DupFilter<IdType: Hash + Eq + Copy + Serialize> {
|
pub struct DupFilter<IdType: Hash + Eq + Copy + Serialize> {
|
||||||
seen_table: HashMap<IdType, ()>,
|
seen_table: HashSet<IdType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A return type indicating whether the item was fresh (not previously
|
/// A return type indicating whether the item was fresh (not previously
|
||||||
|
@ -30,7 +29,7 @@ impl<IdType: Hash + Eq + Copy + Serialize> DupFilter<IdType> {
|
||||||
/// to the seen table. Return Seen if it is already in the table,
|
/// to the seen table. Return Seen if it is already in the table,
|
||||||
/// Fresh if not.
|
/// Fresh if not.
|
||||||
pub fn check(&self, id: &IdType) -> SeenType {
|
pub fn check(&self, id: &IdType) -> SeenType {
|
||||||
if self.seen_table.contains_key(id) {
|
if self.seen_table.contains(id) {
|
||||||
SeenType::Seen
|
SeenType::Seen
|
||||||
} else {
|
} else {
|
||||||
SeenType::Fresh
|
SeenType::Fresh
|
||||||
|
@ -41,9 +40,9 @@ impl<IdType: Hash + Eq + Copy + Serialize> DupFilter<IdType> {
|
||||||
/// table, and add it if not. Return Fresh if it was not already
|
/// table, and add it if not. Return Fresh if it was not already
|
||||||
/// in the table, and Seen if it was.
|
/// in the table, and Seen if it was.
|
||||||
pub fn filter(&mut self, id: &IdType) -> SeenType {
|
pub fn filter(&mut self, id: &IdType) -> SeenType {
|
||||||
match self.seen_table.insert(*id, ()) {
|
match self.seen_table.insert(*id) {
|
||||||
None => SeenType::Fresh,
|
true => SeenType::Fresh,
|
||||||
Some(()) => SeenType::Seen,
|
false => SeenType::Seen,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue