BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
permtypes.c
Go to the documentation of this file.
1 /*
2 This file is part of BitPunch
3 Copyright (C) 2013-2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
4 Copyright (C) 2013-2014 Andrej Gulyas <andrej.guly[what here]gmail.com>
5 Copyright (C) 2013-2014 Marek Klein <kleinmrk[what here]gmail.com>
6 Copyright (C) 2013-2014 Filip Machovec <filipmachovec[what here]yahoo.com>
7 Copyright (C) 2013-2014 Jozef Kudlac <jozef[what here]kudlac.sk>
8 
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "permtypes.h"
23 
24 #include <bitpunch/debugio.h>
25 #include <stdlib.h>
26 
28  if (!*p) {
29  return;
30  }
31  free((*p)->elements);
32  free(*p);
33 }
34 
35 int BPU_permMalloc(BPU_T_Perm_Vector **p, int size) {
36  // allocate memory
37  int i;
38  *p = (BPU_T_Perm_Vector *) calloc(sizeof(BPU_T_Perm_Vector), 1);
39 
40  if (!*p) {
41  BPU_printError("allocation error");
42  return -1;
43  }
44 
45  (*p)->size = size;
46  (*p)->elements = (BPU_T_Perm_Element*) malloc(sizeof(BPU_T_Perm_Element) * size);
47 
48  if (!(*p)->elements) {
49  BPU_printError("BPU_mallocPerm: can not allocate permutation vector");
50 
51  return -1;
52  }
53  for (i = 0; i < (*p)->size; i++) {
54  (*p)->elements[i] = i;
55  }
56  return 0;
57 }
void BPU_permFree(BPU_T_Perm_Vector **p)
Free dynamically or statically alocated permutation vector.
Definition: permtypes.c:27
#define BPU_printError(fmt,...)
print error message with filename, line
Definition: debugio.h:47
uint16_t BPU_T_Perm_Element
Definition of permutation element type.
Definition: permtypes.h:24
int BPU_permMalloc(BPU_T_Perm_Vector **p, int size)
Allocate permutation vector elements of size size.
Definition: permtypes.c:35