Use portable method of zeroing vector of ints.

The memset() technique is only applicable to platforms for which
numerical zero is represented by all bits zero.
This commit is contained in:
Bård Skaflestad
2013-02-01 16:06:39 +01:00
parent 1ca82a7e9f
commit 8f6be16ac3

View File

@@ -20,8 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <string.h>
#include <assert.h>
#include <stddef.h>
#ifdef MATLAB_MEX_FILE
#include "tarjan.h"
@@ -30,7 +30,13 @@ SOFTWARE.
#endif
static void
clear_vector(size_t n, int *v)
{
size_t i;
for (i = 0; i < n; i++) { v[i] = 0; }
}
static int min(int a, int b){ return a < b? a : b;}
@@ -81,11 +87,9 @@ tarjan (int nv, const int *ia, const int *ja, int *vert, int *comp,
int *link = (int *) time + nv;
int *status = (int *) link + nv; /* dual usage... */
(void) cbottom;
memset(work, 0, 3*nv * sizeof *work);
memset(vert, 0, nv * sizeof *vert );
memset(comp, 0, (nv+1) * sizeof *comp );
clear_vector(3 * ((size_t) nv), work);
clear_vector(1 * ((size_t) nv), vert);
clear_vector(1 + ((size_t) nv), comp);
/* Init status all vertices */
for (i=0; i<nv; ++i)