eset.c 1.54 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Project:     libFIRM
 * File name:   ir/adt/eset.c
 * Purpose:     Datentyp: Vereinfachte Menge (hash-set) zum Speichern von
 *              Zeigern/Adressen.
 * Author:      Hubert Schmid
 * Modified by:
 * Created:     09.06.2002
 * CVS-ID:      $Id$
 * Copyright:   (c) 2002 Universitt Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
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
76
77
78
79
80

#include "eset.h"
#include "set.h"


struct eset {
  int dummy; /* dummy entry */
};


static const int INITIAL_SLOTS = 64;


static int pcmp(const void * * p1, const void * * p2, size_t size) {
  return *p1 == *p2 ? 0 : 1;
}


eset * eset_create(void) {
  return (eset *) new_set((set_cmp_fun) pcmp, INITIAL_SLOTS);
}


eset * eset_copy(eset * source) {
  eset * ret = eset_create();
  void * p;
  for (p = eset_first(source); p; p = eset_next(source)) {
    eset_insert(ret, p);
  }
  return ret;
}


void eset_destroy(eset * s) {
  del_set((set *) s);
}


void eset_insert(eset * s, void * p) {
  if (!eset_contains(s, p)) {
    set_insert((set *) s, &p, sizeof(void *), (unsigned) p);
  }
}


bool eset_contains(eset * s, void * p) {
  return set_find((set *) s, &p, sizeof(void *), (unsigned) p) != NULL;
}


void * eset_first(eset * s) {
  void * p = set_first((set *) s);
  return p == NULL ? NULL : *((void * *) p);
}


void * eset_next(eset *s) {
  void * p = set_next((set *) s);
  return p == NULL ? NULL : *((void * *) p);
}


void eset_insert_all(eset * target, eset * source) {
  void * p;
  for (p = eset_first(source); p; p = eset_next(source)) {
    eset_insert(target, p);
  }
}