satsolver  0.17.2
dirpool.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7 #ifndef SATSOLVER_DIRPOOL_H
8 #define SATSOLVER_DIRPOOL_H
9 
10 
11 #include "pooltypes.h"
12 #include "util.h"
13 
14 typedef struct _Dirpool {
15  Id *dirs;
16  int ndirs;
18 } Dirpool;
19 
20 void dirpool_init(Dirpool *dp);
21 void dirpool_free(Dirpool *dp);
22 
24 Id dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create);
25 
26 /* return the parent directory of child did */
27 static inline Id dirpool_parent(Dirpool *dp, Id did)
28 {
29  if (!did)
30  return 0;
31  while (dp->dirs[--did] > 0)
32  ;
33  return -dp->dirs[did];
34 }
35 
36 /* return the next child entry of child did */
37 static inline Id
39 {
40  /* if this block contains another entry, simply return it */
41  if (did + 1 < dp->ndirs && dp->dirs[did + 1] > 0)
42  return did + 1;
43  /* end of block reached, rewind to get to the block's
44  * dirtraverse entry */
45  while (dp->dirs[--did] > 0)
46  ;
47  /* need to special case did == 0 to prevent looping */
48  if (!did)
49  return 0;
50  if (!dp->dirtraverse)
52  return dp->dirtraverse[did];
53 }
54 
55 /* return the first child entry of directory did */
56 static inline Id
58 {
59  if (!dp->dirtraverse)
61  return dp->dirtraverse[did];
62 }
63 
64 static inline void
66 {
67  sat_free(dp->dirtraverse);
68  dp->dirtraverse = 0;
69 }
70 
71 static inline Id
73 {
74  return dp->dirs[did];
75 }
76 
77 #endif /* SATSOLVER_DIRPOOL_H */