]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/blob - zfec/zfec/fec.h
zfec: conditionally-compile the right magic to use alloca() with gcc -mno-cygwin
[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 /**
16  * param k the number of blocks required to reconstruct
17  * param m the total number of blocks created
18  */
19 fec_t* fec_new(unsigned k, unsigned m);
20 void fec_free(fec_t* p);
21
22 /**
23  * @param inpkts the "primary blocks" i.e. the chunks of the input data
24  * @param fecs buffers into which the secondary blocks will be written
25  * @param block_nums the numbers of the desired blocks -- including both primary blocks (the id < k) which fec_encode() ignores and check blocks (the id >= k) which fec_encode() will produce and store into the buffers of the fecs parameter
26  * @param num_block_nums the length of the block_nums array
27  */
28 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);
29
30 /**
31  * @param inpkts an array of packets (size k)
32  * @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)
33  * @param index an array of the blocknums of the packets in inpkts
34  * @param sz size of a packet in bytes
35  */
36 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);
37
38
39 /**
40  * zfec -- fast forward error correction library with Python interface
41  * 
42  * Copyright (C) 2007 Allmydata, Inc.
43  * Author: Zooko Wilcox-O'Hearn
44  * 
45  * This file is part of zfec.
46  * 
47  * This program is free software; you can redistribute it and/or modify it
48  * under the terms of the GNU General Public License as published by the Free
49  * Software Foundation; either version 2 of the License, or (at your option)
50  * any later version, with the added permission that, if you become obligated
51  * to release a derived work under this licence (as per section 2.b), you may
52  * delay the fulfillment of this obligation for up to 12 months.  See the file
53  * COPYING for details.
54  *
55  * If you would like to inquire about a commercial relationship with Allmydata,
56  * Inc., please contact partnerships@allmydata.com and visit
57  * http://allmydata.com/.
58  */
59
60 /*
61  * Much of this work is derived from the "fec" software by Luigi Rizzo, et 
62  * al., the copyright notice and licence terms of which are included below 
63  * for reference.
64  * 
65  * fec.h -- forward error correction based on Vandermonde matrices
66  * 980614
67  * (C) 1997-98 Luigi Rizzo (luigi@iet.unipi.it)
68  *
69  * Portions derived from code by Phil Karn (karn@ka9q.ampr.org),
70  * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari
71  * Thirumoorthy (harit@spectra.eng.hawaii.edu), Aug 1995
72  *
73  * Modifications by Dan Rubenstein (see Modifications.txt for 
74  * their description.
75  * Modifications (C) 1998 Dan Rubenstein (drubenst@cs.umass.edu)
76  *
77  * Redistribution and use in source and binary forms, with or without
78  * modification, are permitted provided that the following conditions
79  * are met:
80
81  * 1. Redistributions of source code must retain the above copyright
82  *    notice, this list of conditions and the following disclaimer.
83  * 2. Redistributions in binary form must reproduce the above
84  *    copyright notice, this list of conditions and the following
85  *    disclaimer in the documentation and/or other materials
86  *    provided with the distribution.
87  *
88  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND
89  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
91  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
92  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
93  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
94  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
95  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
96  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
97  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
98  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
99  * OF SUCH DAMAGE.
100  */
101