Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
3359c1f1
Commit
3359c1f1
authored
May 12, 2023
by
lisj
Browse files
增加GKLib
parent
f2c80b44
Changes
63
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
211 additions
and
0 deletions
+211
-0
third_party/METIS/GKlib/test/strings.c
third_party/METIS/GKlib/test/strings.c
+82
-0
third_party/METIS/GKlib/timers.c
third_party/METIS/GKlib/timers.c
+52
-0
third_party/METIS/GKlib/tokenizer.c
third_party/METIS/GKlib/tokenizer.c
+77
-0
No files found.
third_party/METIS/GKlib/test/strings.c
0 → 100644
View file @
3359c1f1
/*!
\file strings.c
\brief Testing module for the string functions in GKlib
\date Started 3/5/2007
\author George
\version\verbatim $Id: strings.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim
*/
#include <GKlib.h>
/*************************************************************************/
/*! Testing module for gk_strstr_replace() */
/*************************************************************************/
void
test_strstr_replace
()
{
char
*
new_str
;
int
rc
;
rc
=
gk_strstr_replace
(
"This is a simple string"
,
"s"
,
"S"
,
""
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"This is a simple string"
,
"s"
,
"S"
,
"g"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"This is a simple SS & ss string"
,
"s"
,
"T"
,
"g"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"This is a simple SS & ss string"
,
"s"
,
"T"
,
"ig"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"This is a simple SS & ss string"
,
"
\\
b
\\
w(
\\
w+)
\\
w
\\
b"
,
"$1"
,
"ig"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"This is a simple SS & ss string"
,
"
\\
b
\\
w+
\\
b"
,
"word"
,
"ig"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4"
,
"(http://www
\\
.cs
\\
.umn
\\
.edu/)(.*)-T(
\\
d+)"
,
"$1$2-P$3"
,
"g"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4"
,
"(
\\
d+)"
,
"number:$1"
,
"ig"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
rc
=
gk_strstr_replace
(
"http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4"
,
"(http://www
\\
.cs
\\
.umn
\\
.edu/)"
,
"[$1]"
,
"g"
,
&
new_str
);
printf
(
"%d, %s.
\n
"
,
rc
,
new_str
);
gk_free
((
void
**
)
&
new_str
,
LTERM
);
}
int
main
()
{
test_strstr_replace
();
/*
{
int i;
for (i=0; i<1000; i++)
printf("%d\n", RandomInRange(3));
}
*/
}
third_party/METIS/GKlib/timers.c
0 → 100644
View file @
3359c1f1
/*!
\file timers.c
\brief Various timing functions
\date Started 4/12/2007
\author George
\version\verbatim $Id: timers.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim
*/
#include <GKlib.h>
/*************************************************************************
* This function returns the CPU seconds
**************************************************************************/
double
gk_WClockSeconds
(
void
)
{
#ifdef __GNUC__
struct
timeval
ctime
;
gettimeofday
(
&
ctime
,
NULL
);
return
(
double
)
ctime
.
tv_sec
+
(
double
).
000001
*
ctime
.
tv_usec
;
#else
return
(
double
)
time
(
NULL
);
#endif
}
/*************************************************************************
* This function returns the CPU seconds
**************************************************************************/
double
gk_CPUSeconds
(
void
)
{
//#ifdef __OPENMP__
#ifdef __OPENMPXXXX__
return
omp_get_wtime
();
#else
#if defined(WIN32) || defined(__MINGW32__)
return
((
double
)
clock
()
/
CLOCKS_PER_SEC
);
#else
struct
rusage
r
;
getrusage
(
RUSAGE_SELF
,
&
r
);
return
((
r
.
ru_utime
.
tv_sec
+
r
.
ru_stime
.
tv_sec
)
+
1.0e-6
*
(
r
.
ru_utime
.
tv_usec
+
r
.
ru_stime
.
tv_usec
));
#endif
#endif
}
third_party/METIS/GKlib/tokenizer.c
0 → 100644
View file @
3359c1f1
/*!
\file tokenizer.c
\brief String tokenization routines
This file contains various routines for splitting an input string into
tokens and returning them in form of a list. The goal is to mimic perl's
split function.
\date Started 11/23/04
\author George
\version\verbatim $Id: tokenizer.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim
*/
#include <GKlib.h>
/************************************************************************
* This function tokenizes a string based on the user-supplied delimiters
* list. The resulting tokens are returned into an array of strings.
*************************************************************************/
void
gk_strtokenize
(
char
*
str
,
char
*
delim
,
gk_Tokens_t
*
tokens
)
{
int
i
,
ntoks
,
slen
;
tokens
->
strbuf
=
gk_strdup
(
str
);
slen
=
strlen
(
str
);
str
=
tokens
->
strbuf
;
/* Scan once to determine the number of tokens */
for
(
ntoks
=
0
,
i
=
0
;
i
<
slen
;)
{
/* Consume all the consecutive characters from the delimiters list */
while
(
i
<
slen
&&
strchr
(
delim
,
str
[
i
]))
i
++
;
if
(
i
==
slen
)
break
;
ntoks
++
;
/* Consume all the consecutive characters from the token */
while
(
i
<
slen
&&
!
strchr
(
delim
,
str
[
i
]))
i
++
;
}
tokens
->
ntoks
=
ntoks
;
tokens
->
list
=
(
char
**
)
gk_malloc
(
ntoks
*
sizeof
(
char
*
),
"strtokenize: tokens->list"
);
/* Scan a second time to mark and link the tokens */
for
(
ntoks
=
0
,
i
=
0
;
i
<
slen
;)
{
/* Consume all the consecutive characters from the delimiters list */
while
(
i
<
slen
&&
strchr
(
delim
,
str
[
i
]))
str
[
i
++
]
=
'\0'
;
if
(
i
==
slen
)
break
;
tokens
->
list
[
ntoks
++
]
=
str
+
i
;
/* Consume all the consecutive characters from the token */
while
(
i
<
slen
&&
!
strchr
(
delim
,
str
[
i
]))
i
++
;
}
}
/************************************************************************
* This function frees the memory associated with a gk_Tokens_t
*************************************************************************/
void
gk_freetokenslist
(
gk_Tokens_t
*
tokens
)
{
gk_free
((
void
*
)
&
tokens
->
list
,
&
tokens
->
strbuf
,
LTERM
);
}
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment