state-res: Rewrite get_auth_chain_diff algorithm
This commit is contained in:
parent
3a04aea446
commit
6559681095
@ -79,7 +79,7 @@ where
|
|||||||
debug!("{:?}", conflicting);
|
debug!("{:?}", conflicting);
|
||||||
|
|
||||||
// The set of auth events that are not common across server forks
|
// The set of auth events that are not common across server forks
|
||||||
let mut auth_diff = get_auth_chain_diff(auth_chain_sets);
|
let mut auth_diff: HashSet<_> = get_auth_chain_diff(auth_chain_sets).collect();
|
||||||
|
|
||||||
// Add the auth_diff to conflicting now we have a full set of conflicting events
|
// Add the auth_diff to conflicting now we have a full set of conflicting events
|
||||||
auth_diff.extend(conflicting.values().cloned().flatten().flatten());
|
auth_diff.extend(conflicting.values().cloned().flatten().flatten());
|
||||||
@ -194,17 +194,17 @@ pub fn separate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a Vec of deduped EventIds that appear in some chains but not others.
|
/// Returns a Vec of deduped EventIds that appear in some chains but not others.
|
||||||
pub fn get_auth_chain_diff(auth_chain_sets: Vec<HashSet<EventId>>) -> HashSet<EventId> {
|
pub fn get_auth_chain_diff(
|
||||||
if let Some(first) = auth_chain_sets.first().cloned() {
|
auth_chain_sets: Vec<HashSet<EventId>>,
|
||||||
let common = auth_chain_sets
|
) -> impl Iterator<Item = EventId> {
|
||||||
.iter()
|
let num_sets = auth_chain_sets.len();
|
||||||
.skip(1)
|
|
||||||
.fold(first, |a, b| a.intersection(b).cloned().collect::<HashSet<EventId>>());
|
|
||||||
|
|
||||||
auth_chain_sets.into_iter().flatten().filter(|id| !common.contains(id)).collect()
|
let mut id_counts: HashMap<EventId, usize> = HashMap::new();
|
||||||
} else {
|
for id in auth_chain_sets.into_iter().flatten() {
|
||||||
HashSet::new()
|
*id_counts.entry(id).or_default() += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id_counts.into_iter().filter_map(move |(id, count)| (count < num_sets).then(move || id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Events are sorted from "earliest" to "latest".
|
/// Events are sorted from "earliest" to "latest".
|
||||||
|
Loading…
x
Reference in New Issue
Block a user