alloc.cpp
Go to the documentation of this file.
1 // ========================================================================================
2 // ApproxMVBB
3 // Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // ========================================================================================
9 
10 
12 
13 namespace ApproxMVBB{
14 namespace Diameter{
15 
16 void *_AllocateListOfPoints( const int n, const int dim )
17 {
18  void *b = NULL;
19  double **list, **dd;
20  double *d;
21  int i;
22 
23  if ( n <= 0 || dim <= 0 ) return(NULL);
24 
25  b = (void*)malloc( n * sizeof( double* )
26  + n * dim * sizeof( double ) );
27  if ( b == (void *)NULL ) return( (void *)NULL );
28 
29  dd = list = (double **)b;
30  dd += n;
31 
32  d = (double*)dd;
33  for (i=0; i<n; i++, d+=dim ) list[i] = d;
34 
35  return( b );
36 }
37 
38 void *_AllocateListOfSegments( const int n )
39 {
40  void *b = NULL;
41  TypeSegment *d;
42  int i;
43 
44 
45  if ( n <= 0 ) return(NULL);
46 
47  b = (void*)malloc( n * sizeof( TypeSegment ) );
48 
49  if ( b == (void *)NULL ) return( (void *)NULL );
50 
51  d = (TypeSegment *)b;
52  for ( i=0; i<n; i++ ) {
53  d[i].extremity1 = (double*)NULL;
54  d[i].extremity2 = (double*)NULL;
55  d[i].squareDiameter = 0.0;
56  d[i].reduction_mode = 0;
57  }
58 
59  return( b );
60 }
61 
62 #define _NALLOC_ 20
63 
65 {
66  TypeSegment *d;
67 
68  if ( list->nalloc <= 0 )
69  list->n = list->nalloc = 0;
70 
71  if ( list->n >= list->nalloc ) {
72 
74  if ( d == NULL ) {
75  return( 0 );
76  }
77 
78  if ( list->nalloc > 0 ) {
79  memcpy( d, list->seg, list->nalloc*sizeof(TypeSegment) );
80  free( list->seg );
81  }
82 
83  list->nalloc += _NALLOC_;
84  list->seg = d;
85 
86  }
87 
88  list->seg[list->n] = *s;
89  list->n++;
90 
91  return( 1 );
92 }
93 
94 }
95 }
96 
These are some container definitions.
APPROXMVBB_EXPORT int _AddSegmentToList(TypeSegment *s, TypeListOfSegments *list)
Definition: alloc.cpp:64
APPROXMVBB_EXPORT void * _AllocateListOfPoints(const int n, const int dim)
Definition: alloc.cpp:16
APPROXMVBB_EXPORT void * _AllocateListOfSegments(const int n)
Definition: alloc.cpp:38
#define _NALLOC_
Definition: alloc.cpp:62


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Mon Jun 10 2019 12:38:08