Various fixes and cosmetic changes.
[SXSI/libbp.git] / bp.h
diff --git a/bp.h b/bp.h
index b982430..6177b83 100644 (file)
--- a/bp.h
+++ b/bp.h
@@ -114,7 +114,9 @@ static inline int bp_find_open(bp *b,int s)
 ///////////////////////////////////////////
 static inline int bp_parent(bp *b, int s)
 {
-  int r = bp_bwd_excess(b,s,-2);
+  int r;
+  if (bp_getbit(b->B, s - 1) == OP) return s - 1;
+  r = bp_bwd_excess(b,s,-2);
   return (r >= -1) ? r+1 : -1;
 }
 
@@ -228,7 +230,7 @@ static inline int bp_first_child(bp *b, int s)
 static inline int bp_next_sibling(bp *b, int s)
 {
   int t;
-  t = bp_find_close(b,s) + 1;
+  t = bp_find_close(b, s) + 1;
   return (bp_inspect(b, t) == CP) ? -1 : t;
 
 }
@@ -288,6 +290,13 @@ int bp_child(bp *b, int s, int d);
 // new functions for persistence purposes, added by Diego Arroyuelo
 void saveTree(bp *b, FILE *fp);
 bp * loadTree(FILE *fp);
+
+//0: success 1: failure (errno)
+int bp_save(bp *b, int fd);
+
+//non-null: sucess, null: failure (errno)
+
+bp * bp_load(int fd);
 void bp_delete(bp *b);