aboutsummaryrefslogtreecommitdiff
path: root/src/mtx_qhull/entry.h
blob: 956bab1bbe5744e1de93d0011dca915aad792558 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef QHULL_ENTRY_H
#define QHULL_ENTRY_H

#include <sys/types.h>
#include <stdio.h>


/*
 *  variable entry types for
 *  list operations in zhull
 *
 * Copyright (c) 2012, IOhannes zmoelnig,
 * with friendly help from
 * IEM, Graz, Austria
 * 
 *
 */



typedef size_t index_t;

typedef union {
  index_t i;
  void*p;
} entryvalu_t;

typedef enum {
  INDEX,
  POINTER,
  INVALID
} entrytype_t;

typedef struct entry_ {
  entrytype_t typ;
  entryvalu_t val;
} entry_t;

static
void entry_setIndex(entry_t*e, index_t i) {
  e->typ=INDEX;
  e->val.i=i;
}
static
void entry_setPointer(entry_t*e, void*p) {
  e->typ=POINTER;
  e->val.p=p;
}
static
entry_t entry_makeIndex(index_t i) {
  entry_t result;
  entry_setIndex(&result, i);
  return result;
}
static
entry_t entry_makePointer(void*p) {
  entry_t result;
  entry_setPointer(&result, p);
  return result;
}

static
index_t entry_getIndex(const entry_t*e) {
  return (INDEX==e->typ)?e->val.i:0;
}
static
void*entry_getPointer(const entry_t*e) {
  return (POINTER==e->typ)?e->val.p:0;
}
static
int entry_equals(const entry_t*e1, const entry_t*e2) {
  if(e1->typ!=e2->typ)return 0;
  switch(e1->typ) {
  case INDEX:
    return (e1->val.i == e2->val.i);
  case POINTER:
    return (e1->val.p == e2->val.p);
  default:
    return 0;
  }
  return 0;
}

static
void print_entry(const entry_t e) {
    switch(e.typ) {
  case INDEX:
    printf("%lu", (unsigned long)(e.val.i));
    return;
  case POINTER:
    printf("0x%p", e.val.p);
    return;
  default:
    printf("<unkonwn>");
    return;
  }
}





#endif