Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bedtools2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
R3
legacy
bedtools2
Commits
59d77134
Commit
59d77134
authored
13 years ago
by
Aaron
Browse files
Options
Downloads
Patches
Plain Diff
15% speedup for the tokenizer.
parent
45952e64
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utils/lineFileUtilities/lineFileUtilities.h
+23
-31
23 additions, 31 deletions
src/utils/lineFileUtilities/lineFileUtilities.h
with
23 additions
and
31 deletions
src/utils/lineFileUtilities/lineFileUtilities.h
+
23
−
31
View file @
59d77134
...
@@ -3,15 +3,11 @@
...
@@ -3,15 +3,11 @@
#include
<vector>
#include
<vector>
#include
<string>
#include
<string>
#include
<
algorithm
>
#include
<
cstring
>
#include
<sstream>
#include
<sstream>
using
namespace
std
;
using
namespace
std
;
// split a line from a file into a vector of strings. token = "\t"
//void Tokenize(const string &str, vector<string>& tokens, const string &delimiter = "\t");
//void Tokenize(const string &str, vector<int>& tokens, const string &delimiter = "\t");
// templated function to convert objects to strings
// templated function to convert objects to strings
template
<
typename
T
>
template
<
typename
T
>
inline
inline
...
@@ -21,37 +17,33 @@ std::string ToString(const T & value) {
...
@@ -21,37 +17,33 @@ std::string ToString(const T & value) {
return
ss
.
str
();
return
ss
.
str
();
}
}
// tokenize into a list of strings.
inline
inline
void
Tokenize
(
const
string
&
str
,
vector
<
string
>
&
tokens
,
const
string
&
delimiter
=
"
\t
"
)
{
void
Tokenize
(
const
string
&
str
,
vector
<
string
>
&
elems
,
const
string
&
delimiter
=
"
\t
"
)
// Skip delimiters at beginning.
{
string
::
size_type
lastPos
=
str
.
find_first_not_of
(
delimiter
,
0
);
char
*
tok
;
// Find first "non-delimiter".
char
cchars
[
str
.
size
()
+
1
];
string
::
size_type
pos
=
str
.
find_first_of
(
delimiter
,
lastPos
);
char
*
cstr
=
&
cchars
[
0
];
strcpy
(
cstr
,
str
.
c_str
());
while
(
string
::
npos
!=
pos
||
string
::
npos
!=
lastPos
)
{
tok
=
strtok
(
cstr
,
delimiter
.
c_str
());
// Found a token, add it to the vector.
while
(
tok
!=
NULL
)
{
tokens
.
push_back
(
str
.
substr
(
lastPos
,
pos
-
lastPos
));
elems
.
push_back
(
tok
);
// Skip delimiters. Note the "not_of"
tok
=
strtok
(
NULL
,
delimiter
.
c_str
());
lastPos
=
str
.
find_first_not_of
(
delimiter
,
pos
);
// Find next "non-delimiter"
pos
=
str
.
find_first_of
(
delimiter
,
lastPos
);
}
}
}
}
// tokenize into a list of integers
inline
inline
void
Tokenize
(
const
string
&
str
,
vector
<
int
>
&
tokens
,
const
string
&
delimiter
=
"
\t
"
)
{
void
Tokenize
(
const
string
&
str
,
vector
<
int
>
&
elems
,
const
string
&
delimiter
=
"
\t
"
)
// Skip delimiters at beginning.
{
string
::
size_type
lastPos
=
str
.
find_first_not_of
(
delimiter
,
0
);
char
*
tok
;
// Find first "non-delimiter".
char
cchars
[
str
.
size
()
+
1
];
string
::
size_type
pos
=
str
.
find_first_of
(
delimiter
,
lastPos
);
char
*
cstr
=
&
cchars
[
0
];
strcpy
(
cstr
,
str
.
c_str
());
while
(
string
::
npos
!=
pos
||
string
::
npos
!=
lastPos
)
{
tok
=
strtok
(
cstr
,
delimiter
.
c_str
());
// Found a token, add it to the vector.
while
(
tok
!=
NULL
)
{
tokens
.
push_back
(
atoi
(
str
.
substr
(
lastPos
,
pos
-
lastPos
).
c_str
()));
elems
.
push_back
(
atoi
(
tok
));
// Skip delimiters. Note the "not_of"
tok
=
strtok
(
NULL
,
delimiter
.
c_str
());
lastPos
=
str
.
find_first_not_of
(
delimiter
,
pos
);
// Find next "non-delimiter"
pos
=
str
.
find_first_of
(
delimiter
,
lastPos
);
}
}
}
}
...
...
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