File: checkid.c

package info (click to toggle)
iqtree 1.5.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,780 kB
  • ctags: 11,529
  • sloc: cpp: 96,162; ansic: 59,874; python: 242; sh: 189; makefile: 45
file content (122 lines) | stat: -rwxr-xr-x 1,952 bytes parent folder | download | duplicates (5)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "memory.h"

#define CHECK_MASK 0x1c		/* Assumes exactly last two bits are 0 ... */
                                /* ... If not, change checklist dimension  */
typedef struct checkidstruct
{
  int *ID;
  struct checkidstruct *next;
} Checklisttype;

Checklisttype checklist[(CHECK_MASK>>2)+1] = {{NULL,NULL},{NULL,NULL},{NULL,NULL},{NULL,NULL}};


#ifdef __STDC__
int *checkID( int *ptr)
#else
int *checkID(ptr)
int *ptr;
#endif
{
  int bucket;
  Checklisttype *next;
  
  if(ptr == NULL)
    return NULL;
  
  bucket = (((uintptr_t) ptr)&CHECK_MASK)>>2;
  next = checklist[bucket].next;
  
  while(next != NULL)
  {
    if(next->ID == ptr)
    {
      return (int *) ptr;
    }
    else
    {
      next = next->next;
    }
    
  }
  
  fprintf(stderr,"ERROR: Invalid generator ID %p\n", (void *) ptr);
  return NULL;
}



#ifdef __STDC__
int *deleteID( int *ptr)
#else
int *deleteID(ptr)
int *ptr;
#endif
{
  int bucket;
  Checklisttype *next, *temp;
  
  
  if(ptr == NULL)
    return NULL;
  
  bucket = (((uintptr_t) ptr)&CHECK_MASK)>>2;
  next = &checklist[bucket];
  
  while(next->next != NULL)
    if(next->next->ID == ptr)
    {
      temp = next->next;
      next->next = next->next->next;
      
      free(temp);
      return (int *) ptr;
    }
    else
    {
      next = next->next;
    }
  

  fprintf(stderr,"ERROR: Invalid generator ID %p\n", (void *) ptr);
  return NULL;
}


#ifdef __STDC__
int *addID( int *ptr)
#else
int *addID(ptr)
int *ptr;
#endif
{
  int bucket;
  /* Checklisttype *next, *temp; (HAS) */
  Checklisttype *temp;
  
  if(ptr == NULL)
    return NULL;
 
  
  bucket = (((uintptr_t) ptr)&CHECK_MASK)>>2;
  
  temp = (Checklisttype *) mymalloc(sizeof(Checklisttype));
  if(temp == NULL)
    return NULL;
  
  temp->ID = (int *) ptr;
  temp->next = checklist[bucket].next;
  checklist[bucket].next = temp;
  
  
  return (int *) ptr;
}