void test_heapsort (size_t N) { int status; double *orig = (double *) malloc (N * sizeof (double)); double *data = (double *) malloc (N * sizeof (double)); size_t *p = (size_t *) malloc (N * sizeof(size_t)); initialize (orig, N); /* Already sorted */ cpy (data, orig, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, ordered", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, ordered", N); /* Reverse the data */ cpy (data, orig, N); reverse (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, reversed", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, reversed", N); /* Perform some shuffling */ cpy (data, orig, N); randomize (data, N); status = gsl_heapsort_index (p, data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status |= pcheck (p, data, orig, N); gsl_test (status, "indexing array, n = %u, randomized", N); gsl_heapsort (data, N, sizeof (double), (gsl_comparison_fn_t) & cmp_dbl); status = check (data, orig, N); gsl_test (status, "sorting, array, n = %u, randomized", N); free (orig); free (data); free (p); }
static VALUE rb_gsl_heapsort_vector_complex(VALUE obj) { gsl_vector_complex *v = NULL; if (!rb_block_given_p()) rb_raise(rb_eRuntimeError, "Proc is not given"); Data_Get_Struct(obj, gsl_vector_complex, v); gsl_heapsort(v->data, v->size, sizeof(gsl_complex), rb_gsl_comparison_complex); return obj; }
static VALUE rb_gsl_heapsort_vector_complex2(VALUE obj) { gsl_vector_complex *v = NULL, *vnew = NULL; if (!rb_block_given_p()) rb_raise(rb_eRuntimeError, "Proc is not given"); Data_Get_Struct(obj, gsl_vector_complex, v); vnew = gsl_vector_complex_alloc(v->size); gsl_vector_complex_memcpy(vnew, v); gsl_heapsort(vnew->data, vnew->size, sizeof(gsl_complex), rb_gsl_comparison_complex); return Data_Wrap_Struct(cgsl_vector_complex, 0, gsl_vector_complex_free, vnew); }