forked from ludwig-cf/ludwig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolloid_link.c
95 lines (73 loc) · 2.02 KB
/
colloid_link.c
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
/*****************************************************************************
*
* colloid_link.h
*
* Colloid boundary link structure.
*
* $Id: colloid_link.c,v 1.2 2010-10-15 12:40:02 kevin Exp $
*
* Edinburgh Soft Matter and Statistical Physics Group and
* Edinburgh Parallel Computing Centre
*
* Kevin Stratford ([email protected])
* (c) 2010 The University of Edinburgh
*
*****************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include "colloid_link.h"
static int nlinks_ = 0; /* Total currently allocated */
/*****************************************************************************
*
* colloid_link_allocate
*
*****************************************************************************/
colloid_link_t * colloid_link_allocate(void) {
colloid_link_t * p_link;
p_link = (colloid_link_t *) malloc(sizeof(colloid_link_t));
assert(p_link);
nlinks_++;
return p_link;
}
/*****************************************************************************
*
* colloid_link_free_list
*
* Should take the first link in the list as argument.
*
*****************************************************************************/
void colloid_link_free_list(colloid_link_t * p) {
colloid_link_t * tmp;
while (p) {
tmp = p->next;
free(p);
p = tmp;
nlinks_--;
}
return;
}
/*****************************************************************************
*
* colloid_link_count
*
* Should take the first link in the list and returns the number of
* links.
*
*****************************************************************************/
int colloid_link_count(colloid_link_t * p) {
int count = 0;
assert(p);
while (p) {
count++;
p = p->next;
}
return count;
}
/*****************************************************************************
*
* colloid_link_total
*
*****************************************************************************/
int colloid_link_total(void) {
return nlinks_;
}