4 * Copyright (c) 2008-2012 BGI-Shenzhen <soap at genomics dot org dot cn>.
6 * This file is part of SOAPdenovo.
8 * SOAPdenovo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * SOAPdenovo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with SOAPdenovo. If not, see <http://www.gnu.org/licenses/>.
26 DARRAY
* createDarray ( int num_items
, size_t unit_size
)
28 DARRAY
* newDarray
= ( DARRAY
* ) malloc ( 1 * sizeof ( DARRAY
) );
29 newDarray
->array_size
= num_items
;
30 newDarray
->item_size
= unit_size
;
31 newDarray
->item_c
= 0;
32 newDarray
->array
= ( void * ) ckalloc ( num_items
* unit_size
);
36 void * darrayPut ( DARRAY
* darray
, long long index
)
40 if ( index
+ 1 > darray
->item_c
)
42 darray
->item_c
= index
+ 1;
45 if ( index
< darray
->array_size
)
47 return darray
->array
+ darray
->item_size
* index
;
50 while ( index
> i
* darray
->array_size
)
55 darray
->array
= ( void * ) ckrealloc ( darray
->array
, i
* darray
->array_size
* darray
->item_size
, darray
->array_size
* darray
->item_size
);
56 darray
->array_size
*= i
;
57 return ( void * ) ( ( void * ) darray
->array
+ darray
->item_size
* index
);
60 void * darrayGet ( DARRAY
* darray
, long long index
)
62 if ( index
< darray
->array_size
)
64 return ( void * ) ( ( void * ) darray
->array
+ darray
->item_size
* index
);
67 fprintf ( stderr
, "Index %lld of the array is out of range and the size is %lld.\n", index
, darray
->array_size
);
71 void emptyDarray ( DARRAY
* darray
)
76 void freeDarray ( DARRAY
* darray
)
85 free ( ( void * ) darray
->array
);
88 free ( ( void * ) darray
);