Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
44d4806d
Commit
44d4806d
authored
25 years ago
by
Fredrik Hübinette (Hubbe)
Browse files
Options
Downloads
Patches
Plain Diff
now uses introsort
Rev: src/fsort_template.h:1.6
parent
4093941b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/fsort_template.h
+129
-40
129 additions, 40 deletions
src/fsort_template.h
with
129 additions
and
40 deletions
src/fsort_template.h
+
129
−
40
View file @
44d4806d
/*
/*
* $Id: fsort_template.h,v 1.
5
1999/0
4/30 07:25:42
hubbe Exp $
* $Id: fsort_template.h,v 1.
6
1999/0
5/03 07:04:16
hubbe Exp $
*/
*/
#ifndef SWAP
#ifndef SWAP
...
@@ -19,62 +19,151 @@
...
@@ -19,62 +19,151 @@
#define PARENT(X) (((X)-1)>>1)
#define PARENT(X) (((X)-1)>>1)
#define CHILD1(X) (((X)<<1)+1)
#define CHILD1(X) (((X)<<1)+1)
static
void
ID
(
register
TYPE
*
bas
,
#define MKNAME(X) MKNAME2(ID,X)
register
TYPE
*
last
#define MKNAME2(X,Y) PIKE_CONCAT(X,Y)
static
void
MKNAME
(
_do_sort
)(
register
TYPE
*
bas
,
register
TYPE
*
last
,
int
max_recursion
#ifdef EXTRA_ARGS
#ifdef EXTRA_ARGS
EXTRA_ARGS
EXTRA_ARGS
#else
#else
#define UNDEF_XARGS
#define UNDEF_XARGS
#define XARGS
#define XARGS
#endif
#endif
)
)
{
{
register
TYPE
tmp
;
register
TYPE
*
a
,
*
b
,
tmp
;
long
howmany
,
x
,
y
,
z
;
#ifdef PIKE_DEBUG
extern
int
d_flag
;
#endif
howmany
=
((((
char
*
)
last
)
-
((
char
*
)
bas
))
/
SIZE
)
+
1
;
while
(
bas
<
last
)
if
(
howmany
<
2
)
return
;
for
(
x
=
PARENT
(
howmany
-
1
);
x
>=
0
;
x
--
)
{
{
y
=
x
;
a
=
STEP
(
bas
,
1
)
;
while
(
1
)
if
(
a
==
last
)
{
{
z
=
CHILD1
(
y
);
if
(
CMP
(
bas
,
last
)
>
0
)
SWAP
(
bas
,
last
);
if
(
z
>=
howmany
)
break
;
return
;
if
(
z
+
1
<
howmany
&&
CMP
(
STEP
(
bas
,
z
),
STEP
(
bas
,
z
+
1
))
<=
0
)
z
++
;
}
else
{
if
(
CMP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
))
>
0
)
break
;
if
(
--
max_recursion
<=
0
)
SWAP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
));
{
y
=
z
;
long
howmany
,
x
,
y
,
z
;
}
#ifdef PIKE_DEBUG
}
extern
int
d_flag
;
#endif
howmany
=
((((
char
*
)
last
)
-
((
char
*
)
bas
))
/
SIZE
)
+
1
;
if
(
howmany
<
2
)
return
;
for
(
x
=
PARENT
(
howmany
-
1
);
x
>=
0
;
x
--
)
{
y
=
x
;
while
(
1
)
{
z
=
CHILD1
(
y
);
if
(
z
>=
howmany
)
break
;
if
(
z
+
1
<
howmany
&&
CMP
(
STEP
(
bas
,
z
),
STEP
(
bas
,
z
+
1
))
<=
0
)
z
++
;
if
(
CMP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
))
>
0
)
break
;
SWAP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
));
y
=
z
;
}
}
for
(
x
=
howmany
-
1
;
x
;
x
--
)
{
SWAP
(
STEP
(
bas
,
x
),
bas
);
y
=
0
;
while
(
1
)
{
z
=
CHILD1
(
y
);
if
(
z
>=
x
)
break
;
if
(
z
+
1
<
x
&&
CMP
(
STEP
(
bas
,
z
),
STEP
(
bas
,
z
+
1
))
<=
0
)
z
++
;
if
(
CMP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
))
>
0
)
break
;
SWAP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
));
y
=
z
;
}
}
#ifdef PIKE_DEBUG
if
(
d_flag
>
1
)
for
(
x
=
howmany
-
1
;
x
;
x
--
)
if
(
CMP
(
STEP
(
bas
,
x
-
1
),
STEP
(
bas
,
x
)
)
>
0
)
fatal
(
"Sorting failed!
\n
"
);
#endif
return
;
}
for
(
x
=
howmany
-
1
;
x
;
x
--
)
b
=
STEP
(
bas
,((((
char
*
)
last
)
-
((
char
*
)
bas
))
/
SIZE
)
>>
1
);
{
SWAP
(
bas
,
b
);
SWAP
(
STEP
(
bas
,
x
),
bas
);
b
=
last
;
y
=
0
;
while
(
a
<
b
)
while
(
1
)
{
{
#if 1
z
=
CHILD1
(
y
);
while
(
a
<
b
)
if
(
z
>=
x
)
break
;
{
if
(
z
+
1
<
x
&&
CMP
(
STEP
(
bas
,
z
),
STEP
(
bas
,
z
+
1
))
<=
0
)
z
++
;
while
(
1
)
if
(
CMP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
))
>
0
)
break
;
{
SWAP
(
STEP
(
bas
,
y
),
STEP
(
bas
,
z
));
if
(
a
<=
b
&&
CMP
(
a
,
bas
)
<=
0
)
y
=
z
;
INC
(
a
);
else
{
while
(
a
<
b
&&
CMP
(
bas
,
b
)
<=
0
)
DEC
(
b
);
break
;
}
if
(
a
<
b
&&
CMP
(
bas
,
b
)
<=
0
)
DEC
(
b
);
else
{
while
(
a
<=
b
&&
CMP
(
a
,
bas
)
<=
0
)
INC
(
a
);
break
;
}
}
if
(
a
<
b
)
{
SWAP
(
a
,
b
);
INC
(
a
);
if
(
b
>
STEP
(
a
,
1
))
DEC
(
b
);
}
}
#else
while
(
a
<=
b
&&
CMP
(
a
,
bas
)
<
0
)
INC
(
a
);
while
(
a
<
b
&&
CMP
(
bas
,
b
)
<
0
)
DEC
(
b
);
if
(
a
<
b
)
{
SWAP
(
a
,
b
);
INC
(
a
);
if
(
b
>
STEP
(
a
,
1
))
DEC
(
b
);
}
#endif
}
DEC
(
a
);
SWAP
(
a
,
bas
);
DEC
(
a
);
if
(
(
char
*
)
a
-
(
char
*
)
bas
<
(
char
*
)
last
-
(
char
*
)
b
)
{
MKNAME
(
_do_sort
)(
bas
,
a
,
max_recursion
XARGS
);
bas
=
b
;
}
else
{
MKNAME
(
_do_sort
)(
b
,
last
,
max_recursion
XARGS
);
last
=
a
;
}
}
}
}
}
}
#ifdef PIKE_DEBUG
void
ID
(
register
TYPE
*
bas
,
if
(
d_flag
>
1
)
register
TYPE
*
last
for
(
x
=
howmany
-
1
;
x
;
x
--
)
#ifdef EXTRA_ARGS
if
(
CMP
(
STEP
(
bas
,
x
-
1
),
STEP
(
bas
,
x
)
)
>
0
)
EXTRA_ARGS
fatal
(
"Sorting failed!
\n
"
);
#endif
#endif
)
{
extern
int
my_log2
(
unsigned
INT32
x
);
MKNAME
(
_do_sort
)(
bas
,
last
,
my_log2
(
last
-
bas
)
*
2
XARGS
);;
}
}
#undef INC
#undef INC
#undef DEC
#undef DEC
#undef PARENT
#undef PARENT
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment