File: peel_utils.c

package info (click to toggle)
loki 2.4.7.4-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 4,156 kB
  • sloc: ansic: 38,653; yacc: 4,974; lex: 946; makefile: 333; sh: 100
file content (67 lines) | stat: -rw-r--r-- 2,238 bytes parent folder | download | duplicates (6)
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
/****************************************************************************
 *                                                                          *
 *     Loki - Programs for genetic analysis of complex traits using MCMC    *
 *                                                                          *
 *             Simon Heath - University of Washington                       *
 *                                                                          *
 *                        August 1997                                       *
 *                                                                          *
 * peel_util.c:                                                             *
 *                                                                          *
 * Copyright (C) Simon C. Heath 1997, 2000, 2002                            *
 * This is free software.  You can distribute it and/or modify it           *
 * under the terms of the Modified BSD license, see the file COPYING        *
 *                                                                          *
 ****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#ifdef USE_DMALLOC
#include <dmalloc.h>
#endif
#include <math.h>

#include "shared_peel.h"

int num_bits(const int n_all)
{
	int nb;	

	nb=(int)(0.99999+log((double)n_all)/log(2.0));
	return nb;
}

void free_peelseq(struct Peelseq_Head *pp)
{
	struct Simple_Element *simple_em;
	struct Fenris_Simple_Element *fsimple_em;
	struct Complex_Element *complex_em;
	void *old_ptr=0;
	
	while(pp->type) {
		switch(pp->type) {
		 case PEEL_SIMPLE:
			simple_em=pp->ptr.simple;
			if(old_ptr) free(old_ptr);
			pp= &simple_em->next;
			if(simple_em->off) free(simple_em->off);
			old_ptr=(void *)simple_em;
			break;
		 case FENRIS_PEEL_SIMPLE:
			fsimple_em=pp->ptr.fsimple;
			if(old_ptr) free(old_ptr);
			pp= &fsimple_em->next;
			if(fsimple_em->off) free(fsimple_em->off);
			old_ptr=(void *)fsimple_em;
			break;
		 case PEEL_COMPLEX:
			complex_em=pp->ptr.complex;
			if(old_ptr) free(old_ptr);
			pp= &complex_em->next;
			free(complex_em->involved);
			old_ptr=(void *)complex_em;
			break;
		}
	}
	if(old_ptr) free(old_ptr);
}