X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2Flibbp.git;a=blobdiff_plain;f=bp.h;fp=bp.h;h=6177b83e6670560898b967b390ce74def16c75fb;hp=b98243003d024be75d4129881a8f2e96dc4fc989;hb=5382b5fde5add82ebd492e97a458a824503fbd8d;hpb=35d38c5681c54a22125452a2e43dc4b8305c588f diff --git a/bp.h b/bp.h index b982430..6177b83 100644 --- 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);