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
93b97ac9
Commit
93b97ac9
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-io: readAllLines
parent
956421a6
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-io/reader/common/text/tokenizer.ts
+30
-5
30 additions, 5 deletions
src/mol-io/reader/common/text/tokenizer.ts
src/mol-plugin/state/actions/basic.ts
+1
-1
1 addition, 1 deletion
src/mol-plugin/state/actions/basic.ts
with
31 additions
and
6 deletions
src/mol-io/reader/common/text/tokenizer.ts
+
30
−
5
View file @
93b97ac9
...
@@ -52,7 +52,7 @@ export namespace Tokenizer {
...
@@ -52,7 +52,7 @@ export namespace Tokenizer {
/**
/**
* Eat everything until a newline occurs.
* Eat everything until a newline occurs.
*/
*/
export
function
eatLine
(
state
:
Tokenizer
)
{
export
function
eatLine
(
state
:
Tokenizer
)
:
boolean
{
const
{
data
}
=
state
;
const
{
data
}
=
state
;
while
(
state
.
position
<
state
.
length
)
{
while
(
state
.
position
<
state
.
length
)
{
switch
(
data
.
charCodeAt
(
state
.
position
))
{
switch
(
data
.
charCodeAt
(
state
.
position
))
{
...
@@ -60,7 +60,7 @@ export namespace Tokenizer {
...
@@ -60,7 +60,7 @@ export namespace Tokenizer {
state
.
tokenEnd
=
state
.
position
;
state
.
tokenEnd
=
state
.
position
;
++
state
.
position
;
++
state
.
position
;
++
state
.
lineNumber
;
++
state
.
lineNumber
;
return
;
return
true
;
case
13
:
// \r
case
13
:
// \r
state
.
tokenEnd
=
state
.
position
;
state
.
tokenEnd
=
state
.
position
;
++
state
.
position
;
++
state
.
position
;
...
@@ -68,13 +68,14 @@ export namespace Tokenizer {
...
@@ -68,13 +68,14 @@ export namespace Tokenizer {
if
(
data
.
charCodeAt
(
state
.
position
)
===
10
)
{
if
(
data
.
charCodeAt
(
state
.
position
)
===
10
)
{
++
state
.
position
;
++
state
.
position
;
}
}
return
;
return
true
;
default
:
default
:
++
state
.
position
;
++
state
.
position
;
break
;
break
;
}
}
}
}
state
.
tokenEnd
=
state
.
position
;
state
.
tokenEnd
=
state
.
position
;
return
state
.
tokenStart
!==
state
.
tokenEnd
;
}
}
/** Sets the current token start to the current position */
/** Sets the current token start to the current position */
...
@@ -85,7 +86,7 @@ export namespace Tokenizer {
...
@@ -85,7 +86,7 @@ export namespace Tokenizer {
/** Sets the current token start to current position and moves to the next line. */
/** Sets the current token start to current position and moves to the next line. */
export
function
markLine
(
state
:
Tokenizer
)
{
export
function
markLine
(
state
:
Tokenizer
)
{
state
.
tokenStart
=
state
.
position
;
state
.
tokenStart
=
state
.
position
;
eatLine
(
state
);
return
eatLine
(
state
);
}
}
/** Advance the state by the given number of lines and return line starts/ends as tokens. */
/** Advance the state by the given number of lines and return line starts/ends as tokens. */
...
@@ -95,10 +96,13 @@ export namespace Tokenizer {
...
@@ -95,10 +96,13 @@ export namespace Tokenizer {
}
}
function
readLinesChunk
(
state
:
Tokenizer
,
count
:
number
,
tokens
:
Tokens
)
{
function
readLinesChunk
(
state
:
Tokenizer
,
count
:
number
,
tokens
:
Tokens
)
{
let
read
=
0
;
for
(
let
i
=
0
;
i
<
count
;
i
++
)
{
for
(
let
i
=
0
;
i
<
count
;
i
++
)
{
markLine
(
state
);
if
(
!
markLine
(
state
)
)
return
read
;
TokenBuilder
.
addUnchecked
(
tokens
,
state
.
tokenStart
,
state
.
tokenEnd
);
TokenBuilder
.
addUnchecked
(
tokens
,
state
.
tokenStart
,
state
.
tokenEnd
);
read
++
;
}
}
return
read
;
}
}
/** Advance the state by the given number of lines and return line starts/ends as tokens. */
/** Advance the state by the given number of lines and return line starts/ends as tokens. */
...
@@ -124,6 +128,27 @@ export namespace Tokenizer {
...
@@ -124,6 +128,27 @@ export namespace Tokenizer {
return
lineTokens
;
return
lineTokens
;
}
}
export
function
readAllLines
(
data
:
string
)
{
const
state
=
Tokenizer
(
data
);
const
tokens
=
TokenBuilder
.
create
(
state
,
Math
.
max
(
data
.
length
/
160
,
2
))
while
(
markLine
(
state
))
{
TokenBuilder
.
add
(
tokens
,
state
.
tokenStart
,
state
.
tokenEnd
);
}
return
tokens
;
}
export
async
function
readAllLinesAsync
(
data
:
string
,
ctx
:
RuntimeContext
,
chunkSize
=
100000
)
{
const
state
=
Tokenizer
(
data
);
const
tokens
=
TokenBuilder
.
create
(
state
,
Math
.
max
(
data
.
length
/
160
,
2
));
await
chunkedSubtask
(
ctx
,
chunkSize
,
state
,
(
chunkSize
,
state
)
=>
{
readLinesChunk
(
state
,
chunkSize
,
tokens
);
return
state
.
position
<
state
.
length
?
chunkSize
:
0
;
},
(
ctx
,
state
)
=>
ctx
.
update
({
message
:
'
Parsing...
'
,
current
:
state
.
position
,
max
:
length
}));
return
tokens
;
}
/**
/**
* Eat everything until a whitespace/newline occurs.
* Eat everything until a whitespace/newline occurs.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
src/mol-plugin/state/actions/basic.ts
+
1
−
1
View file @
93b97ac9
...
@@ -14,7 +14,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
...
@@ -14,7 +14,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
import
{
PluginStateObject
}
from
'
../objects
'
;
import
{
PluginStateObject
}
from
'
../objects
'
;
import
{
StateTransforms
}
from
'
../transforms
'
;
import
{
StateTransforms
}
from
'
../transforms
'
;
import
{
Download
}
from
'
../transforms/data
'
;
import
{
Download
}
from
'
../transforms/data
'
;
import
{
StructureRepresentation3DHelpers
,
VolumeRepresentation3DHelpers
}
from
'
../transforms/representation
'
;
import
{
StructureRepresentation3DHelpers
}
from
'
../transforms/representation
'
;
import
{
getFileInfo
,
FileInput
}
from
'
mol-util/file-info
'
;
import
{
getFileInfo
,
FileInput
}
from
'
mol-util/file-info
'
;
import
{
Task
}
from
'
mol-task
'
;
import
{
Task
}
from
'
mol-task
'
;
...
...
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