Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Bit_Array.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #include "Bit_Array.h"
20 
21 #include <string.h>
22 
23 void Bit_Array_init( struct Bit_Array *ba, uint64_t size )
24 {
25  ba->real_size = size;
26  ba->size = (size>>3) + 1;
27 
28  ba->array = malloc( ba->size * sizeof( uint8_t ));
29 
30  if( !ba->array ) {
31  printf("Failed to allocate a Bit_Array \n");
32  return;
33  }
34 
35  int i = 0;
36  for( i = 0 ; i < ba->size ; i++ )
37  ba->array[i] = 0;
38 
39 }
40 
41 void Bit_Array_release( struct Bit_Array *ba )
42 {
43  int i = 0;
44  for( i = 0 ; i < ba->size ; i++ )
45  ba->array[i] = 0;
46 
47  ba->size = 0;
48  ba->real_size = 0;
49 
50  free( ba->array );
51  ba->array = NULL;
52 }
53 
54 
55 void Bit_Array_replicate( struct Bit_Array *dest, struct Bit_Array *src )
56 {
57  if( dest->size != src->size )
58  {
59  printf("Trying to copy to a different size Bit_Array\n");
60  abort();
61  }
62 
63  memcpy( dest->array, src->array , dest->size );
64 }
65 
66 
67 
68 void Bit_Array_dump( struct Bit_Array *ba )
69 {
70 
71  int i = 0;
72  unsigned int size = ba->size * 8;
73 
74  printf("Array size is %d \n", size);
75 
76  for( i = 0 ; i < size; i++ ) {
77  printf("[%d]%d ", i, Bit_Array_get( ba, i) );
78  }
79 
80 
81  printf("\n");
82 }
83 
84 
85 
uint8_t * array
The data.
Definition: Bit_Array.h:91
void Bit_Array_dump(struct Bit_Array *ba)
Prints a Bit_Array on standard output.
Definition: Bit_Array.c:68
uint64_t size
The number of uint8_t array contains.
Definition: Bit_Array.h:92
void Bit_Array_release(struct Bit_Array *ba)
Bit_Array deinitializer.
Definition: Bit_Array.c:41
void Bit_Array_init(struct Bit_Array *ba, uint64_t size)
Bit_Array initializer.
Definition: Bit_Array.c:23
uint64_t real_size
The number of bits the array contains.
Definition: Bit_Array.h:93
static uint8_t Bit_Array_get(struct Bit_Array *ba, uint64_t key)
Gets a bit in a Bit_Array.
Definition: Bit_Array.h:167
void Bit_Array_replicate(struct Bit_Array *dest, struct Bit_Array *src)
Copies a Bit_Array into another.
Definition: Bit_Array.c:55
Defines a bit array.
Definition: Bit_Array.h:90