Ajout des fonctions is_next_sibling, is_first_child, prev_sibling et parent_of_first
authorshibing <shibing@shibingdeMacBook-Pro.local>
Tue, 11 Mar 2014 15:13:36 +0000 (16:13 +0100)
committershibing <shibing@shibingdeMacBook-Pro.local>
Tue, 11 Mar 2014 15:13:36 +0000 (16:13 +0100)
src/naive_tree.ml
src/tree.ml

index 38421e0..a13a56d 100644 (file)
@@ -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
index 525f8c7..9e6c71c 100644 (file)
@@ -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