From 1947a98f419c2bf50378fed783406818b010c60e Mon Sep 17 00:00:00 2001 From: shibing Date: Tue, 11 Mar 2014 16:13:36 +0100 Subject: [PATCH] Ajout des fonctions is_next_sibling, is_first_child, prev_sibling et parent_of_first --- src/naive_tree.ml | 7 +++++++ src/tree.ml | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/naive_tree.ml b/src/naive_tree.ml index 38421e0..a13a56d 100644 --- a/src/naive_tree.ml +++ b/src/naive_tree.ml @@ -327,6 +327,13 @@ let root t = t.root let size t = t.size let first_child _ n = n.first_child let next_sibling _ n = n.next_sibling + +let is_first_child _ n = n.parent.first_child == n +let is_next_sibling _ n = n.parent.next_sibling == n + +let prev_sibling t n = if is_next_sibling t n then n.parent else nil +let parent_of_first t n = if is_first_child t n then n.parent else nil + let parent _ n = n.parent let tag _ n = n.tag let data _ n = n.data diff --git a/src/tree.ml b/src/tree.ml index 525f8c7..9e6c71c 100644 --- a/src/tree.ml +++ b/src/tree.ml @@ -113,4 +113,15 @@ sig (** [by_preorder t i] returns the node with preorder [i] *) val print_node : Format.formatter -> node -> unit + + val is_first_child : t -> node -> bool + val is_next_sibling : t -> node -> bool + val prev_sibling : t -> node -> node + (** [prev_sibling t n] returns the previous_sibling of node [n] in tree [t]. + Returns [nil] if [n] is the first child of a node. + *) + val parent_of_first : t -> node -> node + (** [parent_of_first t n] returns the parent of node [n] in tree [t] . + Returns [nil] if [n] isn't the first child of a node. + *) end -- 2.17.1