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"
14 typedef struct _Dirpool {
20 void dirpool_init(Dirpool *dp);
21 void dirpool_free(Dirpool *dp);
23 void dirpool_make_dirtraverse(Dirpool *dp);
24 Id dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create);
26 /* return the parent directory of child did */
27 static inline Id dirpool_parent(Dirpool *dp, Id did)
31 while (dp->dirs[--did] > 0)
33 return -dp->dirs[did];
36 /* return the next child entry of child did */
38 dirpool_sibling(Dirpool *dp, Id did)
40 /* if this block contains another entry, simply return it */
41 if (did + 1 < dp->ndirs && dp->dirs[did + 1] > 0)
43 /* end of block reached, rewind to get to the block's
44 * dirtraverse entry */
45 while (dp->dirs[--did] > 0)
47 /* need to special case did == 0 to prevent looping */
51 dirpool_make_dirtraverse(dp);
52 return dp->dirtraverse[did];
55 /* return the first child entry of directory did */
57 dirpool_child(Dirpool *dp, Id did)
60 dirpool_make_dirtraverse(dp);
61 return dp->dirtraverse[did];
65 dirpool_free_dirtraverse(Dirpool *dp)
67 solv_free(dp->dirtraverse);
72 dirpool_compid(Dirpool *dp, Id did)
77 #endif /* LIBSOLV_DIRPOOL_H */