Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e2e081

Browse files
author
Daniil Anisimov
committed
Refactor the comparator functions.
1 parent6587780 commit1e2e081

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

‎utils.c‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ static intargsort_cmp(const void *a, const void *b);
3232
* Function for qsorting an integer arrays
3333
*/
3434
int
35-
int_cmp(constvoid*a,constvoid*b)
35+
int_cmp(constvoid*arg1,constvoid*arg2)
3636
{
37-
if (*(int*)a<*(int*)b)
37+
intv1=*((constint*)arg1);
38+
intv2=*((constint*)arg2);
39+
40+
if (v1<v2)
3841
return-1;
39-
elseif (*(int*)a>*(int*)b)
42+
elseif (v1>v2)
4043
return1;
4144
else
4245
return0;
@@ -46,11 +49,14 @@ int_cmp(const void *a, const void *b)
4649
* Function for qsorting an double arrays
4750
*/
4851
int
49-
double_cmp(constvoid*a,constvoid*b)
52+
double_cmp(constvoid*arg1,constvoid*arg2)
5053
{
51-
if (*(double*)a<*(double*)b)
54+
doublev1=*((constdouble*)arg1);
55+
doublev2=*((constdouble*)arg2);
56+
57+
if (v1<v2)
5258
return-1;
53-
elseif (*(double*)a>*(double*)b)
59+
elseif (v1>v2)
5460
return1;
5561
else
5662
return0;
@@ -60,12 +66,14 @@ double_cmp(const void *a, const void *b)
6066
* Compares elements for two given indexes
6167
*/
6268
int
63-
argsort_cmp(constvoid*a,constvoid*b)
69+
argsort_cmp(constvoid*arg1,constvoid*arg2)
6470
{
65-
return (*argsort_value_cmp) ((char*)argsort_a+
66-
*((int*)a)*argsort_es,
67-
(char*)argsort_a+
68-
*((int*)b)*argsort_es);
71+
intidx1=*((constint*)arg1);
72+
intidx2=*((constint*)arg2);
73+
char*arr= (char*)argsort_a;
74+
75+
return (*argsort_value_cmp) (&arr[idx1*argsort_es],
76+
&arr[idx2*argsort_es]);
6977
}
7078

7179
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp