summaryrefslogtreecommitdiff
path: root/src/queue.h
blob: 4350d923b0a557f2aa5a4587806cc58b1f3a9395 (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
72
73
74
75
/*
 * Copyright (c) 2007, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * queue.h
 * 
 */

#ifndef SATSOLVER_QUEUE_H
#define SATSOLVER_QUEUE_H

#include "pooltypes.h"

typedef struct _Queue {
  Id *elements;		// current elements
  int count;		// current number of elements (minimal size for elements pointer)
  Id *alloc;		// this is whats actually allocated, elements > alloc if shifted
  int left;		// space left in alloc *after* elements+count
} Queue;


extern void queue_alloc_one(Queue *q);

// clear queue
static inline void
queue_empty(Queue *q)
{
  if (q->alloc)
    {
      q->left += (q->elements - q->alloc) + q->count;
      q->elements = q->alloc;
    }
  else
    q->left += q->count;
  q->count = 0;
}

static inline Id
queue_shift(Queue *q)
{
  if (!q->count)
    return 0;
  q->count--;
  return *q->elements++;
}

static inline void
queue_push(Queue *q, Id id)
{
  if (!q->left)
    queue_alloc_one(q);
  q->elements[q->count++] = id;
  q->left--;
}

static inline void
queue_pushunique(Queue *q, Id id)
{
  int i;
  for (i = q->count; i > 0; )
    if (q->elements[--i] == id)
      return;
  queue_push(q, id);
}

extern void queue_clone(Queue *t, Queue *s);
extern void queue_init(Queue *q);
extern void queue_init_buffer(Queue *q, Id *buf, int size);
extern void queue_free(Queue *q);

#endif /* SATSOLVER_QUEUE_H */