mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-08 07:56:55 -04:00
chore(spaces): simplify the SpaceGraph interfaces
This commit is contained in:
committed by
Stefan Ceriu
parent
04728cc1a6
commit
fbb49e9b65
@@ -45,30 +45,30 @@ impl Default for SpaceGraph {
|
||||
|
||||
impl SpaceGraph {
|
||||
/// Creates a new empty space graph containing no nodes or edges.
|
||||
pub fn new() -> Self {
|
||||
pub(super) fn new() -> Self {
|
||||
Self { nodes: BTreeMap::new() }
|
||||
}
|
||||
|
||||
/// Returns the root nodes of the graph, which are nodes without any
|
||||
/// parents.
|
||||
pub fn root_nodes(&self) -> Vec<&OwnedRoomId> {
|
||||
pub(super) fn root_nodes(&self) -> Vec<&OwnedRoomId> {
|
||||
self.nodes.values().filter(|node| node.parents.is_empty()).map(|node| &node.id).collect()
|
||||
}
|
||||
|
||||
/// Returns the children of a given node. If the node does not exist, it
|
||||
/// returns an empty vector.
|
||||
pub fn children_of(&self, node_id: &OwnedRoomId) -> Vec<&OwnedRoomId> {
|
||||
pub(super) fn children_of(&self, node_id: &OwnedRoomId) -> Vec<&OwnedRoomId> {
|
||||
self.nodes.get(node_id).map_or(vec![], |node| node.children.iter().collect())
|
||||
}
|
||||
|
||||
/// Adds a node to the graph. If the node already exists, it does nothing.
|
||||
pub fn add_node(&mut self, node_id: OwnedRoomId) {
|
||||
pub(super) fn add_node(&mut self, node_id: OwnedRoomId) {
|
||||
self.nodes.entry(node_id.clone()).or_insert(SpaceGraphNode::new(node_id));
|
||||
}
|
||||
|
||||
/// Adds a directed edge from `parent_id` to `child_id`, creating nodes if
|
||||
/// they do not already exist in the graph.
|
||||
pub fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) {
|
||||
pub(super) fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) {
|
||||
self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone()));
|
||||
|
||||
self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id.clone()));
|
||||
@@ -80,7 +80,7 @@ impl SpaceGraph {
|
||||
/// Removes cycles in the graph by performing a depth-first search (DFS) and
|
||||
/// remembering the visited nodes. If a node is revisited while still in the
|
||||
/// current path (i.e. it's on the stack), it indicates a cycle.
|
||||
pub fn remove_cycles(&mut self) {
|
||||
pub(super) fn remove_cycles(&mut self) {
|
||||
let mut visited = BTreeSet::new();
|
||||
let mut stack = BTreeSet::new();
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ impl SpaceRoom {
|
||||
}
|
||||
|
||||
/// Build a `SpaceRoom` from a room already known to this client.
|
||||
pub fn new_from_known(known_room: Room, children_count: u64) -> Self {
|
||||
pub(crate) fn new_from_known(known_room: Room, children_count: u64) -> Self {
|
||||
let room_info = known_room.clone_info();
|
||||
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user