-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex_factory.h
57 lines (50 loc) · 1.45 KB
/
vertex_factory.h
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
/* $Id: vertex_factory.h,v 1.8 2001/12/19 22:32:05 acs Exp $
Written by Adam Siepel, Spring 2001
Copyright 2001, Adam Siepel */
/* "Factory" for vertices, allowing more efficient memory allocation
and deallocation. Compile with -DTHREADSAFE for concurrent access
from multiple threads. */
#ifndef VFACT_H
#define VFACT_H
#ifndef WINNT
#include <pthread.h>
#endif
#define VFSIZE 10000
typedef struct vertex Vertex;
struct vertex
{
int *perm;
unsigned int distance; /* distance from home */
unsigned short best_possible_score; /* score of best possible median */
unsigned short worst_possible_score; /* score of worst possible median */
int d1, d2;
Vertex *next;
};
typedef struct vertex_factory VertexFactory;
struct vertex_factory
{
Vertex **vertices;
int **perms;
int nalloc;
int ngenes;
int capacity;
int length;
int width;
void ( *clear_mem ) ( void * );
void *clear_mem_arg;
int medianNGenes;
Vertex *head;
Vertex *tail;
int uncondensedNumGenes;
#ifdef THREADSAFE
pthread_mutex_t mutex;
#endif
};
VertexFactory *new_vf ( int startsize, int ngenes,
void ( *clear_mem ) ( void * ), void *arg );
Vertex *get_vertex ( VertexFactory * vf );
void return_vertex ( VertexFactory * vf, Vertex * v );
void vf_free ( VertexFactory * vf );
void clean_vf ( VertexFactory * vf, int ngenes,
void ( *clear_mem ) ( void * ), void *arg );
#endif