]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/blob - zfec/zfec/fec.h
doc: fix incorrect API doc which tripped up AGL -- sorry about that!
[tahoe-lafs/zfec.git] / zfec / zfec / fec.h
1 /**
2  * zfec -- fast forward error correction library with Python interface
3  */
4
5 #include <stddef.h>
6
7 typedef unsigned char gf;
8
9 typedef struct {
10   unsigned long magic;
11   unsigned k, n;                     /* parameters of the code */
12   gf* enc_matrix;
13 } fec_t;
14
15 #if defined(_MSC_VER)
16 // actually, some of the flavors (i.e. Enterprise) do support restrict
17 //#define restrict __restrict
18 #define restrict
19 #endif
20
21 /**
22  * param k the number of blocks required to reconstruct
23  * param m the total number of blocks created
24  */
25 fec_t* fec_new(unsigned k, unsigned m);
26 void fec_free(fec_t* p);
27
28 /**
29  * @param inpkts the "primary blocks" i.e. the chunks of the input data
30  * @param fecs buffers into which the secondary blocks will be written
31  * @param block_nums the numbers of the desired check blocks (the id >= k) which fec_encode() will produce and store into the buffers of the fecs parameter
32  * @param num_block_nums the length of the block_nums array
33  */
34 void fec_encode(const fec_t* code, const gf*restrict const*restrict const src, gf*restrict const*restrict const fecs, const unsigned*restrict const block_nums, size_t num_block_nums, size_t sz);
35
36 /**
37  * @param inpkts an array of packets (size k)
38  * @param outpkts an array of buffers into which the reconstructed output packets will be written (only packets which are not present in the inpkts input will be reconstructed and written to outpkts)
39  * @param index an array of the blocknums of the packets in inpkts
40  * @param sz size of a packet in bytes
41  */
42 void fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, size_t sz);
43
44 #if defined(_MSC_VER)
45 #define alloca _alloca
46 #else
47 #ifdef __GNUC__
48 #ifndef alloca
49 #define alloca(x) __builtin_alloca(x)
50 #endif
51 #else
52 #include <alloca.h>
53 #endif
54 #endif
55
56 /**
57  * zfec -- fast forward error correction library with Python interface
58  * 
59  * Copyright (C) 2007 Allmydata, Inc.
60  * Author: Zooko Wilcox-O'Hearn
61  * 
62  * This file is part of zfec.
63  * 
64  * See README.txt for licensing information.
65  */
66
67 /*
68  * Much of this work is derived from the "fec" software by Luigi Rizzo, et 
69  * al., the copyright notice and licence terms of which are included below 
70  * for reference.
71  * 
72  * fec.h -- forward error correction based on Vandermonde matrices
73  * 980614
74  * (C) 1997-98 Luigi Rizzo (luigi@iet.unipi.it)
75  *
76  * Portions derived from code by Phil Karn (karn@ka9q.ampr.org),
77  * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari
78  * Thirumoorthy (harit@spectra.eng.hawaii.edu), Aug 1995
79  *
80  * Modifications by Dan Rubenstein (see Modifications.txt for 
81  * their description.
82  * Modifications (C) 1998 Dan Rubenstein (drubenst@cs.umass.edu)
83  *
84  * Redistribution and use in source and binary forms, with or without
85  * modification, are permitted provided that the following conditions
86  * are met:
87
88  * 1. Redistributions of source code must retain the above copyright
89  *    notice, this list of conditions and the following disclaimer.
90  * 2. Redistributions in binary form must reproduce the above
91  *    copyright notice, this list of conditions and the following
92  *    disclaimer in the documentation and/or other materials
93  *    provided with the distribution.
94  *
95  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
96  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
97  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
98  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
99  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
100  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
101  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
102  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
103  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
104  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
105  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
106  * OF SUCH DAMAGE.
107  */
108