2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
7 #ifndef LIBSOLV_DIRPOOL_H
8 #define LIBSOLV_DIRPOOL_H
11 #include "pooltypes.h"
18 typedef struct _Dirpool {
24 void dirpool_init(Dirpool *dp);
25 void dirpool_free(Dirpool *dp);
27 void dirpool_make_dirtraverse(Dirpool *dp);
28 Id dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create);
30 /* return the parent directory of child did */
31 static inline Id dirpool_parent(Dirpool *dp, Id did)
35 while (dp->dirs[--did] > 0)
37 return -dp->dirs[did];
40 /* return the next child entry of child did */
42 dirpool_sibling(Dirpool *dp, Id did)
44 /* if this block contains another entry, simply return it */
45 if (did + 1 < dp->ndirs && dp->dirs[did + 1] > 0)
47 /* end of block reached, rewind to get to the block's
48 * dirtraverse entry */
49 while (dp->dirs[--did] > 0)
51 /* need to special case did == 0 to prevent looping */
55 dirpool_make_dirtraverse(dp);
56 return dp->dirtraverse[did];
59 /* return the first child entry of directory did */
61 dirpool_child(Dirpool *dp, Id did)
64 dirpool_make_dirtraverse(dp);
65 return dp->dirtraverse[did];
69 dirpool_free_dirtraverse(Dirpool *dp)
71 solv_free(dp->dirtraverse);
76 dirpool_compid(Dirpool *dp, Id did)
85 #endif /* LIBSOLV_DIRPOOL_H */