summaryrefslogtreecommitdiff
path: root/src/dirpool.h
blob: 9cec77049c09e1eeaa5798781eb4b264e6f3565d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */
#ifndef SATSOLVER_DIRPOOL_H
#define SATSOLVER_DIRPOOL_H


#include "pooltypes.h"
#include "util.h"

#define DIR_BLOCK 127

typedef struct _Dirpool {
  Id *dirs;
  int ndirs;
  Id *dirtraverse;
} Dirpool;

void dirpool_create(Dirpool *dp);
void dirpool_make_dirtraverse(Dirpool *dp);
Id dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create);

static inline Id dirpool_parent(Dirpool *dp, Id did)
{
  if (!did)
    return 0;
  while (dp->dirs[--did] > 0)
    ;
  return -dp->dirs[did];
}

static inline Id
dirpool_sibling(Dirpool *dp, Id did)
{
  if (did + 1 < dp->ndirs && dp->dirs[did + 1] > 0)
    return did + 1;
  while (dp->dirs[--did] > 0)
    ;
  /* need to special case did == 0 to prevent looping */
  if (!did)
    return 0;
  if (!dp->dirtraverse)
    dirpool_make_dirtraverse(dp);
  return dp->dirtraverse[did];
}

static inline Id
dirpool_child(Dirpool *dp, Id did)
{
  if (!dp->dirtraverse)
    dirpool_make_dirtraverse(dp);
  return dp->dirtraverse[did];
}

static inline void
dirpool_free_dirtraverse(Dirpool *dp)
{
  sat_free(dp->dirtraverse);
  dp->dirtraverse = 0;
}

static inline Id
dirpool_compid(Dirpool *dp, Id did)
{
  return dp->dirs[did];
}

#endif /* SATSOLVER_DIRPOOL_H */