pub fn reverse_topological_power_sort<E: Event>(
        room_id: &RoomId,
        events_to_sort: &[EventId],
        event_map: &mut EventMap<Arc<E>>,
        auth_diff: &BTreeSet<EventId>,
    ) -> Vec<EventId> {
        debug!("reverse topological sort of power events");

        let mut graph = BTreeMap::new();
        for event_id in events_to_sort.iter() {
            StateResolution::add_event_and_auth_chain_to_graph(
                room_id, &mut graph, event_id, event_map, auth_diff,
            );

            // TODO: if these functions are ever made async here
            // is a good place to yield every once in a while so other
            // tasks can make progress
        }

        // This is used in the `key_fn` passed to the lexico_topo_sort fn
        let mut event_to_pl = BTreeMap::new();
        for event_id in graph.keys() {
            let pl = StateResolution::get_power_level_for_sender(room_id, event_id, event_map);
            info!("{} power level {}", event_id, pl);

            event_to_pl.insert(event_id.clone(), pl);

            // TODO: if these functions are ever made async here
            // is a good place to yield every once in a while so other
            // tasks can make progress
        }

        StateResolution::lexicographical_topological_sort(&graph, |event_id| {
            let ev = event_map.get(event_id).unwrap();
            let pl = event_to_pl.get(event_id).unwrap();

            debug!("{:?}", (-*pl, ev.origin_server_ts(), &ev.event_id()));

            // This return value is the key used for sorting events,
            // events are then sorted by power level, time,
            // and lexically by event_id.
            (-*pl, ev.origin_server_ts(), ev.event_id().clone())
        })
    }
/// Events are sorted from "earliest" to "latest". They are compared using
/// the negative power level (reverse topological ordering), the
/// origin server timestamp and incase of a tie the `EventId`s
/// are compared lexicographically.
///
/// The power level is negative because a higher power level is equated to an
/// earlier (further back in time) origin server timestamp.
Events are sorted from "earliest" to "latest". They are compared using
the negative power level (reverse topological ordering), the
origin server timestamp and incase of a tie the `EventId`s
are compared lexicographically.

The power level is negative because a higher power level is equated to an
earlier (further back in time) origin server timestamp.
Events are sorted from " earliest " to " latest " . They are compared using the negative power level ( reverse topological ordering ) the origin server timestamp and incase of a tie the ` EventId ` s are compared lexicographically . The power level is negative because a higher power level is equated to an earlier ( further back in time ) origin server timestamp .
pub fn reverse_topological_power_sort<E: Event>(
        room_id: &RoomId,
        events_to_sort: &[EventId],
        event_map: &mut EventMap<Arc<E>>,
        auth_diff: &BTreeSet<EventId>,
    ) -> Vec<EventId> {
        debug!("reverse topological sort of power events");
        let mut graph = BTreeMap::new();
        for event_id in events_to_sort.iter() {
            StateResolution::add_event_and_auth_chain_to_graph(
                room_id, &mut graph, event_id, event_map, auth_diff,
            );
            // TODO: if these functions are ever made async here
            // is a good place to yield every once in a while so other
            // tasks can make progress
        }
        // This is used in the `key_fn` passed to the lexico_topo_sort fn
        let mut event_to_pl = BTreeMap::new();
        for event_id in graph.keys() {
            let pl = StateResolution::get_power_level_for_sender(room_id, event_id, event_map);
            info!("{} power level {}", event_id, pl);
            event_to_pl.insert(event_id.clone(), pl);
            // TODO: if these functions are ever made async here
            // is a good place to yield every once in a while so other
            // tasks can make progress
        }
        StateResolution::lexicographical_topological_sort(&graph, |event_id| {
            let ev = event_map.get(event_id).unwrap();
            let pl = event_to_pl.get(event_id).unwrap();
            debug!("{:?}", (-*pl, ev.origin_server_ts(), &ev.event_id()));
            // This return value is the key used for sorting events,
            // events are then sorted by power level, time,
            // and lexically by event_id.
            (-*pl, ev.origin_server_ts(), ev.event_id().clone())
        })
    }
pub fn reverse_topological_power_sort < E : Event > ( room_id : & RoomId , events_to_sort : & [ EventId ] , event_map : & mut EventMap < Arc < E > > , auth_diff : & BTreeSet < EventId > , ) -> Vec < EventId > { debug ! ( " " ) ; let mut graph = BTreeMap :: new ( ) ; for event_id in events_to_sort . iter ( ) { StateResolution :: add_event_and_auth_chain_to_graph ( room_id , & mut graph , event_id , event_map , auth_diff , ) ; // TODO: if these functions are ever made async here // is a good place to yield every once in a while so other // tasks can make progress } // This is used in the `key_fn` passed to the lexico_topo_sort fn let mut event_to_pl = BTreeMap :: new ( ) ; for event_id in graph . keys ( ) { let pl = StateResolution :: get_power_level_for_sender ( room_id , event_id , event_map ) ; info ! ( " " event_id pl ) ; event_to_pl . insert ( event_id . clone ( ) , pl ) ; // TODO: if these functions are ever made async here // is a good place to yield every once in a while so other // tasks can make progress } StateResolution :: lexicographical_topological_sort ( & graph , | event_id | { let ev = event_map . get ( event_id ) . unwrap ( ) ; let pl = event_to_pl . get ( event_id ) . unwrap ( ) ; debug ! ( " " ( pl ev origin_server_ts ( ) ev event_id ( ) ) ) ; // This return value is the key used for sorting events, // events are then sorted by power level, time, // and lexically by event_id. ( - * pl , ev . origin_server_ts ( ) , ev . event_id ( ) . clone ( ) ) } ) }
Events are sorted from "earliest" to "latest".
Events are sorted from " earliest " to " latest " .
room_id
&RoomId
events_to_sort
&[EventId]
event_map
&mut EventMap<Arc<E>>
auth_diff
&BTreeSet<EventId>