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
c0144d82
Commit
c0144d82
authored
3 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
SortedArray: add .isRange, improve .areEqual
parent
de3e819b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-data/int/impl/ordered-set.ts
+1
-1
1 addition, 1 deletion
src/mol-data/int/impl/ordered-set.ts
src/mol-data/int/impl/sorted-array.ts
+3
-1
3 additions, 1 deletion
src/mol-data/int/impl/sorted-array.ts
src/mol-data/int/sorted-array.ts
+1
-0
1 addition, 0 deletions
src/mol-data/int/sorted-array.ts
with
5 additions
and
2 deletions
src/mol-data/int/impl/ordered-set.ts
+
1
−
1
View file @
c0144d82
...
...
@@ -19,7 +19,7 @@ export const ofBounds = I.ofBounds;
export
function
ofSortedArray
(
xs
:
Nums
):
OrderedSetImpl
{
if
(
!
xs
.
length
)
return
Empty
;
// check if the array is just a range
if
(
xs
[
xs
.
length
-
1
]
-
xs
[
0
]
+
1
===
xs
.
length
)
return
I
.
ofRange
(
xs
[
0
],
xs
[
xs
.
length
-
1
]);
if
(
S
.
isRange
(
xs
)
)
return
I
.
ofRange
(
xs
[
0
],
xs
[
xs
.
length
-
1
]);
return
xs
as
any
;
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-data/int/impl/sorted-array.ts
+
3
−
1
View file @
c0144d82
...
...
@@ -22,6 +22,7 @@ export function ofRange(min: number, max: number) {
return
ret
;
}
export
function
is
(
xs
:
any
):
xs
is
Nums
{
return
xs
&&
(
Array
.
isArray
(
xs
)
||
!!
xs
.
buffer
);
}
export
function
isRange
(
xs
:
Nums
)
{
return
xs
[
xs
.
length
-
1
]
-
xs
[
0
]
+
1
===
xs
.
length
;
}
export
function
start
(
xs
:
Nums
)
{
return
xs
[
0
];
}
export
function
end
(
xs
:
Nums
)
{
return
xs
[
xs
.
length
-
1
]
+
1
;
}
...
...
@@ -61,6 +62,7 @@ export function areEqual(a: Nums, b: Nums) {
if
(
a
===
b
)
return
true
;
const
aSize
=
a
.
length
;
if
(
aSize
!==
b
.
length
||
a
[
0
]
!==
b
[
0
]
||
a
[
aSize
-
1
]
!==
b
[
aSize
-
1
])
return
false
;
if
(
isRange
(
a
))
return
true
;
for
(
let
i
=
0
;
i
<
aSize
;
i
++
)
{
if
(
a
[
i
]
!==
b
[
i
])
return
false
;
}
...
...
@@ -340,7 +342,7 @@ export function deduplicate(xs: Nums) {
}
export
function
indicesOf
(
a
:
Nums
,
b
:
Nums
):
Nums
{
if
(
a
===
b
)
return
ofSortedArray
(
createRangeArray
(
0
,
a
.
length
-
1
));
if
(
a
reEqual
(
a
,
b
)
)
return
ofSortedArray
(
createRangeArray
(
0
,
a
.
length
-
1
));
const
{
startI
:
sI
,
startJ
:
sJ
,
endI
,
endJ
}
=
getSuitableIntersectionRange
(
a
,
b
);
let
i
=
sI
,
j
=
sJ
;
...
...
This diff is collapsed.
Click to expand it.
src/mol-data/int/sorted-array.ts
+
1
−
0
View file @
c0144d82
...
...
@@ -17,6 +17,7 @@ namespace SortedArray {
/** create sorted array [min, max) (it does NOT contain the max value) */
export
const
ofBounds
:
<
T
extends
number
=
number
>
(
min
:
T
,
max
:
T
)
=>
SortedArray
<
T
>
=
(
min
,
max
)
=>
Impl
.
ofRange
(
min
,
max
-
1
)
as
any
;
export
const
is
:
<
T
extends
number
=
number
>
(
v
:
any
)
=>
v
is
SortedArray
<
T
>
=
Impl
.
is
as
any
;
export
const
isRange
:
<
T
extends
number
=
number
>
(
array
:
ArrayLike
<
number
>
)
=>
boolean
=
Impl
.
isRange
as
any
;
export
const
has
:
<
T
extends
number
=
number
>
(
array
:
SortedArray
<
T
>
,
x
:
T
)
=>
boolean
=
Impl
.
has
as
any
;
/** Returns the index of `x` in `set` or -1 if not found. */
...
...
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