Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
d99de60e
Commit
d99de60e
authored
Feb 13, 2011
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Portability changes to the st package.
parent
350bedf5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
41 deletions
+75
-41
src/misc/st/st.c
+19
-19
src/misc/st/st.h
+21
-3
src/misc/st/stmm.c
+18
-18
src/misc/st/stmm.h
+17
-1
No files found.
src/misc/st/st.c
View file @
d99de60e
...
@@ -79,7 +79,7 @@ st_init_table(st_compare_func_type compare, st_hash_func_type hash)
...
@@ -79,7 +79,7 @@ st_init_table(st_compare_func_type compare, st_hash_func_type hash)
void
void
st_free_table
(
st_table
*
table
)
st_free_table
(
st_table
*
table
)
{
{
register
st_table_entry
*
ptr
,
*
next
;
st_table_entry
*
ptr
,
*
next
;
int
i
;
int
i
;
for
(
i
=
0
;
i
<
table
->
num_bins
;
i
++
)
{
for
(
i
=
0
;
i
<
table
->
num_bins
;
i
++
)
{
...
@@ -110,10 +110,10 @@ st_free_table(st_table *table)
...
@@ -110,10 +110,10 @@ st_free_table(st_table *table)
}
}
int
int
st_lookup
(
st_table
*
table
,
register
const
char
*
key
,
char
**
value
)
st_lookup
(
st_table
*
table
,
const
char
*
key
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
register
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -130,10 +130,10 @@ st_lookup(st_table *table, register const char *key, char **value)
...
@@ -130,10 +130,10 @@ st_lookup(st_table *table, register const char *key, char **value)
}
}
int
int
st_lookup_int
(
st_table
*
table
,
register
char
*
key
,
int
*
value
)
st_lookup_int
(
st_table
*
table
,
char
*
key
,
int
*
value
)
{
{
int
hash_val
;
int
hash_val
;
register
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -167,11 +167,11 @@ st_lookup_int(st_table *table, register char *key, int *value)
...
@@ -167,11 +167,11 @@ st_lookup_int(st_table *table, register char *key, int *value)
}
}
int
int
st_insert
(
register
st_table
*
table
,
register
const
char
*
key
,
char
*
value
)
st_insert
(
st_table
*
table
,
const
char
*
key
,
char
*
value
)
{
{
int
hash_val
;
int
hash_val
;
st_table_entry
*
newEntry
;
st_table_entry
*
newEntry
;
register
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -188,7 +188,7 @@ st_insert(register st_table *table, register const char *key, char *value)
...
@@ -188,7 +188,7 @@ st_insert(register st_table *table, register const char *key, char *value)
if
(
newEntry
==
NULL
)
{
if
(
newEntry
==
NULL
)
{
return
ST_OUT_OF_MEM
;
return
ST_OUT_OF_MEM
;
}
}
newEntry
->
key
=
key
;
newEntry
->
key
=
(
char
*
)
key
;
newEntry
->
record
=
value
;
newEntry
->
record
=
value
;
newEntry
->
next
=
table
->
bins
[
hash_val
];
newEntry
->
next
=
table
->
bins
[
hash_val
];
table
->
bins
[
hash_val
]
=
newEntry
;
table
->
bins
[
hash_val
]
=
newEntry
;
...
@@ -280,9 +280,9 @@ st_find(st_table *table, char *key, char ***slot)
...
@@ -280,9 +280,9 @@ st_find(st_table *table, char *key, char ***slot)
}
}
static
int
static
int
rehash
(
register
st_table
*
table
)
rehash
(
st_table
*
table
)
{
{
register
st_table_entry
*
ptr
,
*
next
,
**
old_bins
;
st_table_entry
*
ptr
,
*
next
,
**
old_bins
;
int
i
,
old_num_bins
,
hash_val
,
old_num_entries
;
int
i
,
old_num_bins
,
hash_val
,
old_num_entries
;
/* save old values */
/* save old values */
...
@@ -371,11 +371,11 @@ st_copy(st_table *old_table)
...
@@ -371,11 +371,11 @@ st_copy(st_table *old_table)
}
}
int
int
st_delete
(
register
st_table
*
table
,
register
const
char
**
keyp
,
char
**
value
)
st_delete
(
st_table
*
table
,
const
char
**
keyp
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
const
char
*
key
=
*
keyp
;
const
char
*
key
=
*
keyp
;
register
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -394,11 +394,11 @@ st_delete(register st_table *table, register const char **keyp, char **value)
...
@@ -394,11 +394,11 @@ st_delete(register st_table *table, register const char **keyp, char **value)
}
}
int
int
st_delete_int
(
register
st_table
*
table
,
register
long
*
keyp
,
char
**
value
)
st_delete_int
(
st_table
*
table
,
long
*
keyp
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
char
*
key
=
(
char
*
)
*
keyp
;
char
*
key
=
(
char
*
)
*
keyp
;
register
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -417,7 +417,7 @@ st_delete_int(register st_table *table, register long *keyp, char **value)
...
@@ -417,7 +417,7 @@ st_delete_int(register st_table *table, register long *keyp, char **value)
}
}
int
int
st_foreach
(
st_table
*
table
,
enum
st_retval
(
*
func
)(
c
onst
c
har
*
,
char
*
,
char
*
),
char
*
arg
)
st_foreach
(
st_table
*
table
,
enum
st_retval
(
*
func
)(
char
*
,
char
*
,
char
*
),
char
*
arg
)
{
{
st_table_entry
*
ptr
,
**
last
;
st_table_entry
*
ptr
,
**
last
;
enum
st_retval
retval
;
enum
st_retval
retval
;
...
@@ -447,8 +447,8 @@ st_foreach(st_table *table, enum st_retval (*func)(const char *, char *, char *)
...
@@ -447,8 +447,8 @@ st_foreach(st_table *table, enum st_retval (*func)(const char *, char *, char *)
int
int
st_strhash
(
const
char
*
string
,
int
modulus
)
st_strhash
(
const
char
*
string
,
int
modulus
)
{
{
register
int
val
=
0
;
int
val
=
0
;
register
int
c
;
int
c
;
while
((
c
=
*
string
++
)
!=
'\0'
)
{
while
((
c
=
*
string
++
)
!=
'\0'
)
{
val
=
val
*
997
+
c
;
val
=
val
*
997
+
c
;
...
@@ -500,7 +500,7 @@ st_init_gen(st_table *table)
...
@@ -500,7 +500,7 @@ st_init_gen(st_table *table)
int
int
st_gen
(
st_generator
*
gen
,
const
char
**
key_p
,
char
**
value_p
)
st_gen
(
st_generator
*
gen
,
const
char
**
key_p
,
char
**
value_p
)
{
{
register
int
i
;
int
i
;
if
(
gen
->
entry
==
NULL
)
{
if
(
gen
->
entry
==
NULL
)
{
/* try to find next entry */
/* try to find next entry */
...
@@ -527,7 +527,7 @@ st_gen(st_generator *gen, const char **key_p, char **value_p)
...
@@ -527,7 +527,7 @@ st_gen(st_generator *gen, const char **key_p, char **value_p)
int
int
st_gen_int
(
st_generator
*
gen
,
const
char
**
key_p
,
long
*
value_p
)
st_gen_int
(
st_generator
*
gen
,
const
char
**
key_p
,
long
*
value_p
)
{
{
register
int
i
;
int
i
;
if
(
gen
->
entry
==
NULL
)
{
if
(
gen
->
entry
==
NULL
)
{
/* try to find next entry */
/* try to find next entry */
...
...
src/misc/st/st.h
View file @
d99de60e
...
@@ -14,17 +14,35 @@
...
@@ -14,17 +14,35 @@
#ifndef ST_INCLUDED
#ifndef ST_INCLUDED
#define ST_INCLUDED
#define ST_INCLUDED
#include "abc_global.h"
#include "abc_global.h"
ABC_NAMESPACE_HEADER_START
ABC_NAMESPACE_HEADER_START
/* These are potential duplicates. */
#ifndef EXTERN
# ifdef __cplusplus
# ifdef ABC_NAMESPACE
# define EXTERN extern
# else
# define EXTERN extern "C"
# endif
# else
# define EXTERN extern
# endif
#endif
#ifndef ARGS
#define ARGS(protos) protos
#endif
typedef
int
(
*
st_compare_func_type
)(
const
char
*
,
const
char
*
);
typedef
int
(
*
st_compare_func_type
)(
const
char
*
,
const
char
*
);
typedef
int
(
*
st_hash_func_type
)(
const
char
*
,
int
);
typedef
int
(
*
st_hash_func_type
)(
const
char
*
,
int
);
typedef
struct
st_table_entry
st_table_entry
;
typedef
struct
st_table_entry
st_table_entry
;
struct
st_table_entry
{
struct
st_table_entry
{
c
onst
c
har
*
key
;
char
*
key
;
char
*
record
;
char
*
record
;
st_table_entry
*
next
;
st_table_entry
*
next
;
};
};
...
@@ -53,7 +71,7 @@ struct st_generator {
...
@@ -53,7 +71,7 @@ struct st_generator {
enum
st_retval
{
ST_CONTINUE
,
ST_STOP
,
ST_DELETE
};
enum
st_retval
{
ST_CONTINUE
,
ST_STOP
,
ST_DELETE
};
typedef
enum
st_retval
(
*
ST_PFSR
)(
c
onst
c
har
*
,
char
*
,
char
*
);
typedef
enum
st_retval
(
*
ST_PFSR
)(
char
*
,
char
*
,
char
*
);
typedef
int
(
*
ST_PFI
)();
typedef
int
(
*
ST_PFI
)();
extern
st_table
*
st_init_table_with_params
(
st_compare_func_type
compare
,
st_hash_func_type
hash
,
int
size
,
int
density
,
double
grow_factor
,
int
reorder_flag
);
extern
st_table
*
st_init_table_with_params
(
st_compare_func_type
compare
,
st_hash_func_type
hash
,
int
size
,
int
density
,
double
grow_factor
,
int
reorder_flag
);
...
...
src/misc/st/stmm.c
View file @
d99de60e
...
@@ -79,7 +79,7 @@ void
...
@@ -79,7 +79,7 @@ void
stmm_free_table
(
stmm_table
*
table
)
stmm_free_table
(
stmm_table
*
table
)
{
{
/*
/*
register
stmm_table_entry *ptr, *next;
stmm_table_entry *ptr, *next;
int i;
int i;
for ( i = 0; i < table->num_bins; i++ )
for ( i = 0; i < table->num_bins; i++ )
{
{
...
@@ -131,10 +131,10 @@ stmm_clean (stmm_table *table)
...
@@ -131,10 +131,10 @@ stmm_clean (stmm_table *table)
}
}
int
int
stmm_lookup
(
stmm_table
*
table
,
register
char
*
key
,
char
**
value
)
stmm_lookup
(
stmm_table
*
table
,
char
*
key
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
register
stmm_table_entry
*
ptr
,
**
last
;
stmm_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -153,10 +153,10 @@ stmm_lookup (stmm_table *table, register char *key, char **value)
...
@@ -153,10 +153,10 @@ stmm_lookup (stmm_table *table, register char *key, char **value)
}
}
int
int
stmm_lookup_int
(
stmm_table
*
table
,
register
char
*
key
,
int
*
value
)
stmm_lookup_int
(
stmm_table
*
table
,
char
*
key
,
int
*
value
)
{
{
int
hash_val
;
int
hash_val
;
register
stmm_table_entry
*
ptr
,
**
last
;
stmm_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -197,11 +197,11 @@ stmm_lookup_int (stmm_table *table, register char *key, int *value)
...
@@ -197,11 +197,11 @@ stmm_lookup_int (stmm_table *table, register char *key, int *value)
}
}
int
int
stmm_insert
(
register
stmm_table
*
table
,
register
char
*
key
,
char
*
value
)
stmm_insert
(
stmm_table
*
table
,
char
*
key
,
char
*
value
)
{
{
int
hash_val
;
int
hash_val
;
stmm_table_entry
*
newEntry
;
stmm_table_entry
*
newEntry
;
register
stmm_table_entry
*
ptr
,
**
last
;
stmm_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -325,9 +325,9 @@ stmm_find (stmm_table *table, char *key, char ***slot)
...
@@ -325,9 +325,9 @@ stmm_find (stmm_table *table, char *key, char ***slot)
}
}
static
int
static
int
rehash
(
register
stmm_table
*
table
)
rehash
(
stmm_table
*
table
)
{
{
register
stmm_table_entry
*
ptr
,
*
next
,
**
old_bins
;
stmm_table_entry
*
ptr
,
*
next
,
**
old_bins
;
int
i
,
old_num_bins
,
hash_val
,
old_num_entries
;
int
i
,
old_num_bins
,
hash_val
,
old_num_entries
;
/* save old values */
/* save old values */
...
@@ -431,11 +431,11 @@ stmm_copy (stmm_table *old_table)
...
@@ -431,11 +431,11 @@ stmm_copy (stmm_table *old_table)
}
}
int
int
stmm_delete
(
register
stmm_table
*
table
,
register
char
**
keyp
,
char
**
value
)
stmm_delete
(
stmm_table
*
table
,
char
**
keyp
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
char
*
key
=
*
keyp
;
char
*
key
=
*
keyp
;
register
stmm_table_entry
*
ptr
,
**
last
;
stmm_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -457,11 +457,11 @@ stmm_delete (register stmm_table *table, register char **keyp, char **value)
...
@@ -457,11 +457,11 @@ stmm_delete (register stmm_table *table, register char **keyp, char **value)
}
}
int
int
stmm_delete_int
(
register
stmm_table
*
table
,
register
long
*
keyp
,
char
**
value
)
stmm_delete_int
(
stmm_table
*
table
,
long
*
keyp
,
char
**
value
)
{
{
int
hash_val
;
int
hash_val
;
char
*
key
=
(
char
*
)
*
keyp
;
char
*
key
=
(
char
*
)
*
keyp
;
register
stmm_table_entry
*
ptr
,
**
last
;
stmm_table_entry
*
ptr
,
**
last
;
hash_val
=
do_hash
(
key
,
table
);
hash_val
=
do_hash
(
key
,
table
);
...
@@ -515,10 +515,10 @@ stmm_foreach (stmm_table *table, enum stmm_retval (*func) (char *, char *, char
...
@@ -515,10 +515,10 @@ stmm_foreach (stmm_table *table, enum stmm_retval (*func) (char *, char *, char
}
}
int
int
stmm_strhash
(
register
const
char
*
string
,
int
modulus
)
stmm_strhash
(
const
char
*
string
,
int
modulus
)
{
{
register
int
val
=
0
;
int
val
=
0
;
register
int
c
;
int
c
;
while
((
c
=
*
string
++
)
!=
'\0'
)
{
while
((
c
=
*
string
++
)
!=
'\0'
)
{
val
=
val
*
997
+
c
;
val
=
val
*
997
+
c
;
...
@@ -570,7 +570,7 @@ stmm_init_gen (stmm_table *table)
...
@@ -570,7 +570,7 @@ stmm_init_gen (stmm_table *table)
int
int
stmm_gen
(
stmm_generator
*
gen
,
char
**
key_p
,
char
**
value_p
)
stmm_gen
(
stmm_generator
*
gen
,
char
**
key_p
,
char
**
value_p
)
{
{
register
int
i
;
int
i
;
if
(
gen
->
entry
==
NULL
)
{
if
(
gen
->
entry
==
NULL
)
{
/* try to find next entry */
/* try to find next entry */
...
@@ -597,7 +597,7 @@ stmm_gen (stmm_generator *gen, char **key_p, char **value_p)
...
@@ -597,7 +597,7 @@ stmm_gen (stmm_generator *gen, char **key_p, char **value_p)
int
int
stmm_gen_int
(
stmm_generator
*
gen
,
char
**
key_p
,
long
*
value_p
)
stmm_gen_int
(
stmm_generator
*
gen
,
char
**
key_p
,
long
*
value_p
)
{
{
register
int
i
;
int
i
;
if
(
gen
->
entry
==
NULL
)
{
if
(
gen
->
entry
==
NULL
)
{
/* try to find next entry */
/* try to find next entry */
...
...
src/misc/st/stmm.h
View file @
d99de60e
...
@@ -17,9 +17,25 @@
...
@@ -17,9 +17,25 @@
#include "extra.h"
#include "extra.h"
ABC_NAMESPACE_HEADER_START
ABC_NAMESPACE_HEADER_START
/* These are potential duplicates. */
#ifndef EXTERN
# ifdef __cplusplus
# ifdef ABC_NAMESPACE
# define EXTERN extern
# else
# define EXTERN extern "C"
# endif
# else
# define EXTERN extern
# endif
#endif
#ifndef ARGS
#define ARGS(protos) protos
#endif
typedef
int
(
*
stmm_compare_func_type
)(
const
char
*
,
const
char
*
);
typedef
int
(
*
stmm_compare_func_type
)(
const
char
*
,
const
char
*
);
typedef
int
(
*
stmm_hash_func_type
)(
const
char
*
,
int
);
typedef
int
(
*
stmm_hash_func_type
)(
const
char
*
,
int
);
...
...
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