Added IsFirstChild and LastChild
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Thu, 16 Apr 2009 00:44:32 +0000 (00:44 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Thu, 16 Apr 2009 00:44:32 +0000 (00:44 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@311 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index 99d0395..249143c 100644 (file)
@@ -357,7 +357,9 @@ bool XMLTree::IsChild(treeNode x, treeNode y)
     if (!is_ancestor(Par, x, y)) return false;\r
     return depth(Par, x) == (depth(Par, y) + 1);\r
  }\r
-\r
+bool XMLTree::IsFirstChild(treeNode x){\r
+  return ((x != NULLT)&&(x==Root() || prev_sibling(Par,x) == NULLT));\r
+}\r
 // NumChildren(x): number of children of node x. Constant time with the data structure\r
 // of Sadakane.\r
 int XMLTree::NumChildren(treeNode x) \r
@@ -499,6 +501,14 @@ treeNode XMLTree::FirstChild(treeNode x)
     return first_child(Par, x);\r
  }\r
 \r
+treeNode XMLTree::LastChild(treeNode x) \r
+{\r
+  if (x == Root() || isleaf(Par,x) || x == NULLT)\r
+    return x;\r
+  else\r
+  return find_open(Par,find_close(Par,parent(Par,x))-1);\r
+}\r
+\r
 // NextSibling(x): returns the next sibling of node x, assuming it exists.\r
 treeNode XMLTree::NextSibling(treeNode x) \r
  {\r
index 9b79ae3..1268cb6 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -153,6 +153,9 @@ public:
   \r
    /** IsChild(x,y): returns whether node x is parent of node y. */\r
    bool IsChild(treeNode x, treeNode y);\r
+\r
+   /** IsChild(x,y): returns whether node x is the first child of its parent */\r
+   bool IsFirstChild(treeNode x);\r
    \r
    /** NumChildren(x): number of children of node x. Constant time with the \r
     * data structure of Sadakane. */\r
@@ -191,8 +194,13 @@ public:
     * Very fast in BP. */\r
    treeNode FirstChild(treeNode x);\r
    \r
+   /** LastChild(x): returns the last child of node x. \r
+    * Implemented by Kim naively. */\r
+   treeNode LastChild(treeNode x);\r
+\r
    /** NextSibling(x): returns the next sibling of node x, assuming it \r
     * exists. */\r
+\r
    treeNode NextSibling(treeNode x);\r
    \r
    /** PrevSibling(x): returns the previous sibling of node x, assuming it \r