Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Goulet
Tor
Commits
4d3d99fa
Commit
4d3d99fa
authored
Dec 13, 2003
by
Roger Dingledine
Browse files
extend smartlist with a few smarter operations
svn:r910
parent
325935b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/common/util.c
View file @
4d3d99fa
...
...
@@ -92,6 +92,7 @@ void smartlist_add(smartlist_t *sl, void *element) {
log_fn
(
LOG_WARN
,
"We've already got %d elements, discarding."
,
sl
->
max
);
}
#if 0
void smartlist_remove(smartlist_t *sl, void *element) {
int i;
if(element == NULL)
...
...
@@ -102,6 +103,33 @@ void smartlist_remove(smartlist_t *sl, void *element) {
i--; /* so we process the new i'th element */
}
}
#endif
int
smartlist_isin
(
smartlist_t
*
sl
,
void
*
element
)
{
int
i
;
for
(
i
=
0
;
i
<
sl
->
num_used
;
i
++
)
if
(
sl
->
list
[
i
]
==
element
)
return
1
;
return
0
;
}
int
smartlist_overlap
(
smartlist_t
*
sl1
,
smartlist_t
*
sl2
)
{
int
i
;
for
(
i
=
0
;
i
<
sl2
->
num_used
;
i
++
)
if
(
smartlist_isin
(
sl1
,
sl2
->
list
[
i
]))
return
1
;
return
0
;
}
/* remove elements of sl1 that aren't in sl2 */
void
smartlist_intersect
(
smartlist_t
*
sl1
,
smartlist_t
*
sl2
)
{
int
i
;
for
(
i
=
0
;
i
<
sl1
->
num_used
;
i
++
)
if
(
!
smartlist_isin
(
sl2
,
sl1
->
list
[
i
]))
{
sl1
->
list
[
i
]
=
sl1
->
list
[
--
sl1
->
num_used
];
/* swap with the end */
i
--
;
/* so we process the new i'th element */
}
}
void
*
smartlist_choose
(
smartlist_t
*
sl
)
{
if
(
sl
->
num_used
)
...
...
src/common/util.h
View file @
4d3d99fa
...
...
@@ -48,7 +48,9 @@ typedef struct {
smartlist_t
*
smartlist_create
(
int
max_elements
);
void
smartlist_free
(
smartlist_t
*
sl
);
void
smartlist_add
(
smartlist_t
*
sl
,
void
*
element
);
void
smartlist_remove
(
smartlist_t
*
sl
,
void
*
element
);
int
smartlist_isin
(
smartlist_t
*
sl
,
void
*
element
);
int
smartlist_overlap
(
smartlist_t
*
sl1
,
smartlist_t
*
sl2
);
void
smartlist_intersect
(
smartlist_t
*
sl1
,
smartlist_t
*
sl2
);
void
*
smartlist_choose
(
smartlist_t
*
sl
);
const
char
*
eat_whitespace
(
const
char
*
s
);
...
...
Write
Preview
Supports
Markdown
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