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
c6c34425
Commit
c6c34425
authored
6 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
added IntervalIterator
parent
0f22f538
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/mol-data/util/_spec/interval-iterator.spec.ts
+33
-0
33 additions, 0 deletions
src/mol-data/util/_spec/interval-iterator.spec.ts
src/mol-data/util/interval-iterator.ts
+45
-0
45 additions, 0 deletions
src/mol-data/util/interval-iterator.ts
with
78 additions
and
0 deletions
src/mol-data/util/_spec/interval-iterator.spec.ts
0 → 100644
+
33
−
0
View file @
c6c34425
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import
{
Interval
,
OrderedSet
,
SortedArray
}
from
'
../../int
'
;
import
{
IntervalIterator
}
from
'
../interval-iterator
'
;
describe
(
'
interval
'
,
()
=>
{
function
testIterator
(
name
:
string
,
interval
:
Interval
,
set
:
OrderedSet
,
expectedValues
:
{
index
:
number
[],
start
:
number
[],
end
:
number
[]})
{
it
(
`iterator,
${
name
}
`
,
()
=>
{
const
intervalIt
=
new
IntervalIterator
(
interval
,
set
)
const
{
index
,
start
,
end
}
=
expectedValues
let
i
=
0
while
(
intervalIt
.
hasNext
)
{
const
segment
=
intervalIt
.
move
()
expect
(
segment
.
index
).
toBe
(
index
[
i
])
expect
(
segment
.
start
).
toBe
(
start
[
i
])
expect
(
segment
.
end
).
toBe
(
end
[
i
])
++
i
}
expect
(
i
).
toBe
(
index
.
length
)
})
}
testIterator
(
'
basic
'
,
Interval
.
ofRange
(
0
,
5
),
SortedArray
.
ofSortedArray
([
1
,
3
,
7
,
8
]),
{
index
:
[
1
,
3
],
start
:
[
0
,
1
],
end
:
[
1
,
2
]
}
)
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-data/util/interval-iterator.ts
0 → 100644
+
45
−
0
View file @
c6c34425
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import
Iterator
from
'
../iterator
'
import
{
OrderedSet
,
Interval
,
Segmentation
}
from
'
../int
'
;
/** Emits a segment of length one for each element in the interval that is also in the set */
export
class
IntervalIterator
<
T
extends
number
=
number
>
implements
Iterator
<
Segmentation
.
Segment
<
T
>>
{
private
value
:
Segmentation
.
Segment
<
T
>
=
{
index
:
0
,
start
:
0
as
T
,
end
:
0
as
T
}
private
curIndex
=
0
private
maxIndex
=
0
hasNext
:
boolean
=
false
;
updateValue
()
{
this
.
value
.
index
=
this
.
curIndex
this
.
value
.
start
=
OrderedSet
.
findPredecessorIndex
(
this
.
set
,
Interval
.
getAt
(
this
.
interval
,
this
.
curIndex
))
as
T
this
.
value
.
end
=
this
.
value
.
start
+
1
as
T
}
move
()
{
if
(
this
.
hasNext
)
{
this
.
updateValue
()
while
(
this
.
curIndex
<=
this
.
maxIndex
)
{
++
this
.
curIndex
if
(
OrderedSet
.
has
(
this
.
set
,
this
.
curIndex
))
break
}
this
.
hasNext
=
this
.
curIndex
<=
this
.
maxIndex
}
return
this
.
value
;
}
constructor
(
private
interval
:
Interval
<
T
>
,
private
set
:
OrderedSet
<
T
>
)
{
if
(
Interval
.
size
(
interval
))
{
this
.
curIndex
=
Interval
.
findPredecessorIndex
(
interval
,
OrderedSet
.
min
(
set
))
this
.
maxIndex
=
Interval
.
findPredecessorIndex
(
interval
,
OrderedSet
.
max
(
set
))
}
this
.
hasNext
=
OrderedSet
.
areIntersecting
(
this
.
interval
,
this
.
set
)
}
}
\ No newline at end of file
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