Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
6a80405a
Commit
6a80405a
authored
7 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
sorting fixes
parent
fc4473e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/structure/collections/sort.ts
+18
-3
18 additions, 3 deletions
src/structure/collections/sort.ts
src/structure/spec/collections.spec.ts
+4
-2
4 additions, 2 deletions
src/structure/spec/collections.spec.ts
with
22 additions
and
5 deletions
src/structure/collections/sort.ts
+
18
−
3
View file @
6a80405a
...
@@ -84,9 +84,24 @@ function partitionArrayAsc(data: number[], parts: number[], l: number, r: number
...
@@ -84,9 +84,24 @@ function partitionArrayAsc(data: number[], parts: number[], l: number, r: number
parts
[
1
]
=
tail
;
parts
[
1
]
=
tail
;
}
}
function
insertionSort
({
data
,
cmp
,
swap
}:
Ctx
,
start
:
number
,
end
:
number
)
{
for
(
let
i
=
start
+
1
;
i
<=
end
;
i
++
)
{
let
j
=
i
-
1
;
while
(
j
>=
start
&&
cmp
(
data
,
j
,
j
+
1
)
>
0
)
{
swap
(
data
,
j
,
j
+
1
);
j
=
j
-
1
;
}
}
}
function
quickSort
(
ctx
:
Ctx
,
low
:
number
,
high
:
number
)
{
function
quickSort
(
ctx
:
Ctx
,
low
:
number
,
high
:
number
)
{
const
{
parts
}
=
ctx
;
const
{
parts
}
=
ctx
;
while
(
low
<
high
)
{
while
(
low
<
high
)
{
if
(
high
-
low
<
16
)
{
insertionSort
(
ctx
,
low
,
high
);
return
;
}
partitionGeneric
(
ctx
,
low
,
high
);
partitionGeneric
(
ctx
,
low
,
high
);
const
li
=
parts
[
0
],
ri
=
parts
[
1
];
const
li
=
parts
[
0
],
ri
=
parts
[
1
];
...
@@ -100,11 +115,11 @@ function quickSort(ctx: Ctx, low: number, high: number) {
...
@@ -100,11 +115,11 @@ function quickSort(ctx: Ctx, low: number, high: number) {
}
}
}
}
function
insertionSort
(
data
:
number
[],
start
:
number
,
end
:
number
)
{
function
insertionSort
ArrayAsc
(
data
:
number
[],
start
:
number
,
end
:
number
)
{
for
(
let
i
=
start
+
1
;
i
<=
end
;
i
++
)
{
for
(
let
i
=
start
+
1
;
i
<=
end
;
i
++
)
{
const
key
=
data
[
i
];
const
key
=
data
[
i
];
let
j
=
i
-
1
;
let
j
=
i
-
1
;
while
(
j
>=
0
&&
data
[
j
]
>
key
)
{
while
(
j
>=
start
&&
data
[
j
]
>
key
)
{
data
[
j
+
1
]
=
data
[
j
];
data
[
j
+
1
]
=
data
[
j
];
j
=
j
-
1
;
j
=
j
-
1
;
}
}
...
@@ -115,7 +130,7 @@ function insertionSort(data: number[], start: number, end: number) {
...
@@ -115,7 +130,7 @@ function insertionSort(data: number[], start: number, end: number) {
function
quickSortArrayAsc
(
data
:
number
[],
parts
:
number
[],
low
:
number
,
high
:
number
)
{
function
quickSortArrayAsc
(
data
:
number
[],
parts
:
number
[],
low
:
number
,
high
:
number
)
{
while
(
low
<
high
)
{
while
(
low
<
high
)
{
if
(
high
-
low
<
16
)
{
if
(
high
-
low
<
16
)
{
insertionSort
(
data
,
low
,
high
);
insertionSort
ArrayAsc
(
data
,
low
,
high
);
return
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/structure/spec/collections.spec.ts
+
4
−
2
View file @
6a80405a
...
@@ -50,7 +50,8 @@ function shuffleArray(data: any[]) {
...
@@ -50,7 +50,8 @@ function shuffleArray(data: any[]) {
}
}
describe
(
'
qsort-array asc
'
,
()
=>
{
describe
(
'
qsort-array asc
'
,
()
=>
{
const
data0
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
];
const
data0
=
new
Array
(
50
);
for
(
let
i
=
0
;
i
<
data0
.
length
;
i
++
)
data0
[
i
]
=
i
;
const
data1
=
[
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
4
,
6
,
6
,
6
];
const
data1
=
[
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
4
,
6
,
6
,
6
];
function
test
(
name
:
string
,
data
:
any
[],
randomize
:
boolean
)
{
function
test
(
name
:
string
,
data
:
any
[],
randomize
:
boolean
)
{
...
@@ -72,7 +73,8 @@ describe('qsort-array asc', () => {
...
@@ -72,7 +73,8 @@ describe('qsort-array asc', () => {
})
})
describe
(
'
qsort-array generic
'
,
()
=>
{
describe
(
'
qsort-array generic
'
,
()
=>
{
const
data0
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
];
const
data0
=
new
Array
(
50
);
for
(
let
i
=
0
;
i
<
data0
.
length
;
i
++
)
data0
[
i
]
=
i
;
const
data1
=
[
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
4
,
6
,
6
,
6
];
const
data1
=
[
1
,
1
,
2
,
2
,
3
,
3
,
4
,
4
,
4
,
6
,
6
,
6
];
function
test
(
name
:
string
,
data
:
any
[],
randomize
:
boolean
)
{
function
test
(
name
:
string
,
data
:
any
[],
randomize
:
boolean
)
{
...
...
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