-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle_hashtab.c
80 lines (63 loc) · 1.45 KB
/
particle_hashtab.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
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <tlhash.h>
#include "sph.h"
static tlhash_t *particles;
void
particles_init ( void )
{
particles = malloc ( sizeof(tlhash_t) );
tlhash_init ( particles, 4096 );
}
void
particles_finalize ( void )
{
tlhash_finalize ( particles );
free ( particles );
}
void
insert_particle ( particle_t *p )
{
tlhash_insert ( particles, &(p->idx), sizeof(int_t), (void *)p );
}
void
lookup_particle ( int_t index, particle_t **p )
{
tlhash_lookup ( particles, &index, sizeof(int_t), (void **)p );
}
void
remove_particle ( particle_t *p )
{
tlhash_remove ( particles, &(p->idx), sizeof(int_t) );
}
void
list_particles ( particle_t **list_point )
{
tlhash_values ( particles, (void **)list_point );
}
/* NB - stack allocation of particle pointer list */
void
marshal_particles ( particle_t *list_point )
{
int_t my_particles = n_particles();
particle_t *actual_ptr[my_particles];
list_particles ( &(actual_ptr[0]) );
for ( int_t i=0; i<my_particles; i++ )
memcpy ( &(list_point[i]), actual_ptr[i], sizeof(particle_t) );
}
void
unmarshal_particles ( particle_t *list, int_t count )
{
for ( int_t k=0; k<count; k++ )
{
particle_t *listed = &(list[k]), *tabbed;
lookup_particle ( listed->idx, &tabbed );
memcpy ( tabbed, listed, sizeof(particle_t) );
}
}
int_t
n_particles ( void )
{
return (int_t)tlhash_size ( particles );
}