Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
f4cb5d8c
Commit
f4cb5d8c
authored
21 years ago
by
Roger Dingledine
Browse files
Options
Downloads
Patches
Plain Diff
extend smartlist with _remove() and _subtract()
svn:r922
parent
2997ef8d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/common/util.c
+18
-0
18 additions, 0 deletions
src/common/util.c
src/common/util.h
+2
-0
2 additions, 0 deletions
src/common/util.h
with
20 additions
and
0 deletions
src/common/util.c
+
18
−
0
View file @
f4cb5d8c
...
...
@@ -92,6 +92,17 @@ void smartlist_add(smartlist_t *sl, void *element) {
log_fn
(
LOG_WARN
,
"We've already got %d elements, discarding."
,
sl
->
max
);
}
void
smartlist_remove
(
smartlist_t
*
sl
,
void
*
element
)
{
int
i
;
if
(
element
==
NULL
)
return
;
for
(
i
=
0
;
i
<
sl
->
num_used
;
i
++
)
if
(
sl
->
list
[
i
]
==
element
)
{
sl
->
list
[
i
]
=
sl
->
list
[
--
sl
->
num_used
];
/* swap with the end */
i
--
;
/* so we process the new i'th element */
}
}
int
smartlist_isin
(
smartlist_t
*
sl
,
void
*
element
)
{
int
i
;
for
(
i
=
0
;
i
<
sl
->
num_used
;
i
++
)
...
...
@@ -118,6 +129,13 @@ void smartlist_intersect(smartlist_t *sl1, smartlist_t *sl2) {
}
}
/* remove all elements of sl2 from sl1 */
void
smartlist_subtract
(
smartlist_t
*
sl1
,
smartlist
*
sl2
)
{
int
i
;
for
(
i
=
0
;
i
<
sl2
->
num_used
;
i
++
)
smartlist_remove
(
sl1
,
sl2
->
list
[
i
]);
}
void
*
smartlist_choose
(
smartlist_t
*
sl
)
{
if
(
sl
->
num_used
)
return
sl
->
list
[
crypto_pseudo_rand_int
(
sl
->
num_used
)];
...
...
This diff is collapsed.
Click to expand it.
src/common/util.h
+
2
−
0
View file @
f4cb5d8c
...
...
@@ -48,9 +48,11 @@ 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_subtract
(
smartlist_t
*
sl1
,
smartlist
*
sl2
);
void
*
smartlist_choose
(
smartlist_t
*
sl
);
const
char
*
eat_whitespace
(
const
char
*
s
);
...
...
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