Rename *_isin to *_contains

This is an automatically generated commit, from the following perl script,
run with the options "-w -i -p".

  s/smartlist_string_num_isin/smartlist_contains_int_as_string/g;
  s/smartlist_string_isin((?:_case)?)/smartlist_contains_string$1/g;
  s/smartlist_digest_isin/smartlist_contains_digest/g;
  s/smartlist_isin/smartlist_contains/g;
  s/digestset_isin/digestset_contains/g;
This commit is contained in:
Nick Mathewson 2012-04-11 12:50:50 -04:00
parent e4821fa14d
commit 49e619c1cf
20 changed files with 94 additions and 94 deletions

View File

@ -2758,7 +2758,7 @@ tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex)
EnterCriticalSection(&cond->mutex); EnterCriticalSection(&cond->mutex);
tor_assert(WaitForSingleObject(event, 0) == WAIT_TIMEOUT); tor_assert(WaitForSingleObject(event, 0) == WAIT_TIMEOUT);
tor_assert(!smartlist_isin(cond->events, event)); tor_assert(!smartlist_contains(cond->events, event));
smartlist_add(cond->events, event); smartlist_add(cond->events, event);
LeaveCriticalSection(&cond->mutex); LeaveCriticalSection(&cond->mutex);

View File

@ -163,7 +163,7 @@ smartlist_string_remove(smartlist_t *sl, const char *element)
/** Return true iff some element E of sl has E==element. /** Return true iff some element E of sl has E==element.
*/ */
int int
smartlist_isin(const smartlist_t *sl, const void *element) smartlist_contains(const smartlist_t *sl, const void *element)
{ {
int i; int i;
for (i=0; i < sl->num_used; i++) for (i=0; i < sl->num_used; i++)
@ -176,7 +176,7 @@ smartlist_isin(const smartlist_t *sl, const void *element)
* !strcmp(E,<b>element</b>) * !strcmp(E,<b>element</b>)
*/ */
int int
smartlist_string_isin(const smartlist_t *sl, const char *element) smartlist_contains_string(const smartlist_t *sl, const char *element)
{ {
int i; int i;
if (!sl) return 0; if (!sl) return 0;
@ -203,7 +203,7 @@ smartlist_string_pos(const smartlist_t *sl, const char *element)
* !strcasecmp(E,<b>element</b>) * !strcasecmp(E,<b>element</b>)
*/ */
int int
smartlist_string_isin_case(const smartlist_t *sl, const char *element) smartlist_contains_string_case(const smartlist_t *sl, const char *element)
{ {
int i; int i;
if (!sl) return 0; if (!sl) return 0;
@ -217,11 +217,11 @@ smartlist_string_isin_case(const smartlist_t *sl, const char *element)
* to the decimal encoding of <b>num</b>. * to the decimal encoding of <b>num</b>.
*/ */
int int
smartlist_string_num_isin(const smartlist_t *sl, int num) smartlist_contains_int_as_string(const smartlist_t *sl, int num)
{ {
char buf[32]; /* long enough for 64-bit int, and then some. */ char buf[32]; /* long enough for 64-bit int, and then some. */
tor_snprintf(buf,sizeof(buf),"%d", num); tor_snprintf(buf,sizeof(buf),"%d", num);
return smartlist_string_isin(sl, buf); return smartlist_contains_string(sl, buf);
} }
/** Return true iff the two lists contain the same strings in the same /** Return true iff the two lists contain the same strings in the same
@ -247,7 +247,7 @@ smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2)
* tor_memeq(E,<b>element</b>,DIGEST_LEN) * tor_memeq(E,<b>element</b>,DIGEST_LEN)
*/ */
int int
smartlist_digest_isin(const smartlist_t *sl, const char *element) smartlist_contains_digest(const smartlist_t *sl, const char *element)
{ {
int i; int i;
if (!sl) return 0; if (!sl) return 0;
@ -257,19 +257,19 @@ smartlist_digest_isin(const smartlist_t *sl, const char *element)
return 0; return 0;
} }
/** Return true iff some element E of sl2 has smartlist_isin(sl1,E). /** Return true iff some element E of sl2 has smartlist_contains(sl1,E).
*/ */
int int
smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2) smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2)
{ {
int i; int i;
for (i=0; i < sl2->num_used; i++) for (i=0; i < sl2->num_used; i++)
if (smartlist_isin(sl1, sl2->list[i])) if (smartlist_contains(sl1, sl2->list[i]))
return 1; return 1;
return 0; return 0;
} }
/** Remove every element E of sl1 such that !smartlist_isin(sl2,E). /** Remove every element E of sl1 such that !smartlist_contains(sl2,E).
* Does not preserve the order of sl1. * Does not preserve the order of sl1.
*/ */
void void
@ -277,13 +277,13 @@ smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2)
{ {
int i; int i;
for (i=0; i < sl1->num_used; i++) for (i=0; i < sl1->num_used; i++)
if (!smartlist_isin(sl2, sl1->list[i])) { if (!smartlist_contains(sl2, sl1->list[i])) {
sl1->list[i] = sl1->list[--sl1->num_used]; /* swap with the end */ sl1->list[i] = sl1->list[--sl1->num_used]; /* swap with the end */
i--; /* so we process the new i'th element */ i--; /* so we process the new i'th element */
} }
} }
/** Remove every element E of sl1 such that smartlist_isin(sl2,E). /** Remove every element E of sl1 such that smartlist_contains(sl2,E).
* Does not preserve the order of sl1. * Does not preserve the order of sl1.
*/ */
void void

View File

@ -35,13 +35,13 @@ void smartlist_remove(smartlist_t *sl, const void *element);
void *smartlist_pop_last(smartlist_t *sl); void *smartlist_pop_last(smartlist_t *sl);
void smartlist_reverse(smartlist_t *sl); void smartlist_reverse(smartlist_t *sl);
void smartlist_string_remove(smartlist_t *sl, const char *element); void smartlist_string_remove(smartlist_t *sl, const char *element);
int smartlist_isin(const smartlist_t *sl, const void *element); int smartlist_contains(const smartlist_t *sl, const void *element);
int smartlist_string_isin(const smartlist_t *sl, const char *element); int smartlist_contains_string(const smartlist_t *sl, const char *element);
int smartlist_string_pos(const smartlist_t *, const char *elt); int smartlist_string_pos(const smartlist_t *, const char *elt);
int smartlist_string_isin_case(const smartlist_t *sl, const char *element); int smartlist_contains_string_case(const smartlist_t *sl, const char *element);
int smartlist_string_num_isin(const smartlist_t *sl, int num); int smartlist_contains_int_as_string(const smartlist_t *sl, int num);
int smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2); int smartlist_strings_eq(const smartlist_t *sl1, const smartlist_t *sl2);
int smartlist_digest_isin(const smartlist_t *sl, const char *element); int smartlist_contains_digest(const smartlist_t *sl, const char *element);
int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2); int smartlist_overlap(const smartlist_t *sl1, const smartlist_t *sl2);
void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2); void smartlist_intersect(smartlist_t *sl1, const smartlist_t *sl2);
void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2); void smartlist_subtract(smartlist_t *sl1, const smartlist_t *sl2);
@ -623,7 +623,7 @@ digestset_add(digestset_t *set, const char *digest)
/** If <b>digest</b> is in <b>set</b>, return nonzero. Otherwise, /** If <b>digest</b> is in <b>set</b>, return nonzero. Otherwise,
* <em>probably</em> return zero. */ * <em>probably</em> return zero. */
static INLINE int static INLINE int
digestset_isin(const digestset_t *set, const char *digest) digestset_contains(const digestset_t *set, const char *digest)
{ {
const uint32_t *p = (const uint32_t *)digest; const uint32_t *p = (const uint32_t *)digest;
const uint32_t d1 = p[0] + (p[1]>>16); const uint32_t d1 = p[0] + (p[1]>>16);

View File

@ -2301,7 +2301,7 @@ circuit_all_predicted_ports_handled(time_t now, int *need_uptime,
enough = (smartlist_len(sl) == 0); enough = (smartlist_len(sl) == 0);
for (i = 0; i < smartlist_len(sl); ++i) { for (i = 0; i < smartlist_len(sl); ++i) {
port = smartlist_get(sl, i); port = smartlist_get(sl, i);
if (smartlist_string_num_isin(LongLivedServices, *port)) if (smartlist_contains_int_as_string(LongLivedServices, *port))
*need_uptime = 1; *need_uptime = 1;
tor_free(port); tor_free(port);
} }

View File

@ -1611,10 +1611,10 @@ assert_circuit_ok(const circuit_t *c)
} }
if (c->state == CIRCUIT_STATE_CHAN_WAIT && !c->marked_for_close) { if (c->state == CIRCUIT_STATE_CHAN_WAIT && !c->marked_for_close) {
tor_assert(circuits_pending_chans && tor_assert(circuits_pending_chans &&
smartlist_isin(circuits_pending_chans, c)); smartlist_contains(circuits_pending_chans, c));
} else { } else {
tor_assert(!circuits_pending_chans || tor_assert(!circuits_pending_chans ||
!smartlist_isin(circuits_pending_chans, c)); !smartlist_contains(circuits_pending_chans, c));
} }
if (origin_circ && origin_circ->cpath) { if (origin_circ && origin_circ->cpath) {
assert_cpath_ok(origin_circ->cpath); assert_cpath_ok(origin_circ->cpath);

View File

@ -804,7 +804,7 @@ circuit_stream_is_being_handled(entry_connection_t *conn,
const node_t *exitnode; const node_t *exitnode;
int num=0; int num=0;
time_t now = time(NULL); time_t now = time(NULL);
int need_uptime = smartlist_string_num_isin(get_options()->LongLivedPorts, int need_uptime = smartlist_contains_int_as_string(get_options()->LongLivedPorts,
conn ? conn->socks_request->port : port); conn ? conn->socks_request->port : port);
for (circ=global_circuitlist;circ;circ = circ->next) { for (circ=global_circuitlist;circ;circ = circ->next) {
@ -1621,7 +1621,7 @@ circuit_get_open_circ_or_launch(entry_connection_t *conn,
want_onehop = conn->want_onehop; want_onehop = conn->want_onehop;
need_uptime = !conn->want_onehop && !conn->use_begindir && need_uptime = !conn->want_onehop && !conn->use_begindir &&
smartlist_string_num_isin(options->LongLivedPorts, smartlist_contains_int_as_string(options->LongLivedPorts,
conn->socks_request->port); conn->socks_request->port);
if (desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL) if (desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL)

View File

@ -829,9 +829,9 @@ static int
consider_plaintext_ports(entry_connection_t *conn, uint16_t port) consider_plaintext_ports(entry_connection_t *conn, uint16_t port)
{ {
const or_options_t *options = get_options(); const or_options_t *options = get_options();
int reject = smartlist_string_num_isin(options->RejectPlaintextPorts, port); int reject = smartlist_contains_int_as_string(options->RejectPlaintextPorts, port);
if (smartlist_string_num_isin(options->WarnPlaintextPorts, port)) { if (smartlist_contains_int_as_string(options->WarnPlaintextPorts, port)) {
log_warn(LD_APP, "Application request to port %d: this port is " log_warn(LD_APP, "Application request to port %d: this port is "
"commonly used for unencrypted protocols. Please make sure " "commonly used for unencrypted protocols. Please make sure "
"you don't send anything you would mind the rest of the " "you don't send anything you would mind the rest of the "

View File

@ -3110,7 +3110,7 @@ dirvote_compute_consensuses(void)
} }
tor_assert(pending_vote_list); tor_assert(pending_vote_list);
SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v, { SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v, {
if (smartlist_string_isin(v->vote->known_flags, "Running")) if (smartlist_contains_string(v->vote->known_flags, "Running"))
n_vote_running++; n_vote_running++;
}); });
if (!n_vote_running) { if (!n_vote_running) {

View File

@ -1218,7 +1218,7 @@ is_test_address(const char *address)
{ {
const or_options_t *options = get_options(); const or_options_t *options = get_options();
return options->ServerDNSTestAddresses && return options->ServerDNSTestAddresses &&
smartlist_string_isin_case(options->ServerDNSTestAddresses, address); smartlist_contains_string_case(options->ServerDNSTestAddresses, address);
} }
/** Called on the OR side when the eventdns library tells us the outcome of a /** Called on the OR side when the eventdns library tells us the outcome of a
@ -1843,7 +1843,7 @@ wildcard_increment_answer(const char *id)
if (*ip > 5 && n_wildcard_requests > 10) { if (*ip > 5 && n_wildcard_requests > 10) {
if (!dns_wildcard_list) dns_wildcard_list = smartlist_new(); if (!dns_wildcard_list) dns_wildcard_list = smartlist_new();
if (!smartlist_string_isin(dns_wildcard_list, id)) { if (!smartlist_contains_string(dns_wildcard_list, id)) {
log(dns_wildcard_notice_given ? LOG_INFO : LOG_NOTICE, LD_EXIT, log(dns_wildcard_notice_given ? LOG_INFO : LOG_NOTICE, LD_EXIT,
"Your DNS provider has given \"%s\" as an answer for %d different " "Your DNS provider has given \"%s\" as an answer for %d different "
"invalid addresses. Apparently they are hijacking DNS failures. " "invalid addresses. Apparently they are hijacking DNS failures. "
@ -1866,7 +1866,7 @@ add_wildcarded_test_address(const char *address)
if (!dns_wildcarded_test_address_list) if (!dns_wildcarded_test_address_list)
dns_wildcarded_test_address_list = smartlist_new(); dns_wildcarded_test_address_list = smartlist_new();
if (smartlist_string_isin_case(dns_wildcarded_test_address_list, address)) if (smartlist_contains_string_case(dns_wildcarded_test_address_list, address))
return; return;
n_test_addrs = get_options()->ServerDNSTestAddresses ? n_test_addrs = get_options()->ServerDNSTestAddresses ?
@ -2104,7 +2104,7 @@ dns_reset_correctness_checks(void)
static int static int
answer_is_wildcarded(const char *ip) answer_is_wildcarded(const char *ip)
{ {
return dns_wildcard_list && smartlist_string_isin(dns_wildcard_list, ip); return dns_wildcard_list && smartlist_contains_string(dns_wildcard_list, ip);
} }
/** Exit with an assertion if <b>resolve</b> is corrupt. */ /** Exit with an assertion if <b>resolve</b> is corrupt. */

View File

@ -762,7 +762,7 @@ entry_guards_set_from_config(const or_options_t *options)
smartlist_add(entry_fps, (void*)node->identity)); smartlist_add(entry_fps, (void*)node->identity));
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e, { SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e, {
if (smartlist_digest_isin(entry_fps, e->identity)) if (smartlist_contains_digest(entry_fps, e->identity))
smartlist_add(old_entry_guards_on_list, e); smartlist_add(old_entry_guards_on_list, e);
else else
smartlist_add(old_entry_guards_not_on_list, e); smartlist_add(old_entry_guards_not_on_list, e);
@ -901,7 +901,7 @@ choose_random_entry_impl(cpath_build_state_t *state, int for_directory,
} }
if (node == chosen_exit) if (node == chosen_exit)
continue; /* don't pick the same node for entry and exit */ continue; /* don't pick the same node for entry and exit */
if (consider_exit_family && smartlist_isin(exit_family, node)) if (consider_exit_family && smartlist_contains(exit_family, node))
continue; /* avoid relays that are family members of our exit */ continue; /* avoid relays that are family members of our exit */
#if 0 /* since EntryNodes is always strict now, this clause is moot */ #if 0 /* since EntryNodes is always strict now, this clause is moot */
if (options->EntryNodes && if (options->EntryNodes &&

View File

@ -422,7 +422,7 @@ connection_unlink(connection_t *conn)
void void
add_connection_to_closeable_list(connection_t *conn) add_connection_to_closeable_list(connection_t *conn)
{ {
tor_assert(!smartlist_isin(closeable_connection_lst, conn)); tor_assert(!smartlist_contains(closeable_connection_lst, conn));
tor_assert(conn->marked_for_close); tor_assert(conn->marked_for_close);
assert_connection_ok(conn, time(NULL)); assert_connection_ok(conn, time(NULL));
smartlist_add(closeable_connection_lst, conn); smartlist_add(closeable_connection_lst, conn);
@ -432,14 +432,14 @@ add_connection_to_closeable_list(connection_t *conn)
int int
connection_is_on_closeable_list(connection_t *conn) connection_is_on_closeable_list(connection_t *conn)
{ {
return smartlist_isin(closeable_connection_lst, conn); return smartlist_contains(closeable_connection_lst, conn);
} }
/** Return true iff conn is in the current poll array. */ /** Return true iff conn is in the current poll array. */
int int
connection_in_array(connection_t *conn) connection_in_array(connection_t *conn)
{ {
return smartlist_isin(connection_array, conn); return smartlist_contains(connection_array, conn);
} }
/** Set <b>*array</b> to an array of all connections, and <b>*n</b> /** Set <b>*array</b> to an array of all connections, and <b>*n</b>
@ -666,7 +666,7 @@ connection_start_reading_from_linked_conn(connection_t *conn)
tor_event_base_loopexit(tor_libevent_get_base(), &tv); tor_event_base_loopexit(tor_libevent_get_base(), &tv);
} }
} else { } else {
tor_assert(smartlist_isin(active_linked_connection_lst, conn)); tor_assert(smartlist_contains(active_linked_connection_lst, conn));
} }
} }
@ -686,7 +686,7 @@ connection_stop_reading_from_linked_conn(connection_t *conn)
* so let's leave it alone for now. */ * so let's leave it alone for now. */
smartlist_remove(active_linked_connection_lst, conn); smartlist_remove(active_linked_connection_lst, conn);
} else { } else {
tor_assert(!smartlist_isin(active_linked_connection_lst, conn)); tor_assert(!smartlist_contains(active_linked_connection_lst, conn));
} }
} }

View File

@ -774,7 +774,7 @@ router_set_networkstatus_v2(const char *s, time_t arrived_at,
} }
if (requested_fingerprints) { if (requested_fingerprints) {
if (smartlist_string_isin(requested_fingerprints, fp)) { if (smartlist_contains_string(requested_fingerprints, fp)) {
smartlist_string_remove(requested_fingerprints, fp); smartlist_string_remove(requested_fingerprints, fp);
} else { } else {
if (source != NS_FROM_DIR_ALL) { if (source != NS_FROM_DIR_ALL) {

View File

@ -374,7 +374,7 @@ addr_is_in_cc_list(uint32_t addr, const smartlist_t *cc_list)
tor_addr_from_ipv4h(&tar, addr); tor_addr_from_ipv4h(&tar, addr);
country = geoip_get_country_by_addr(&tar); country = geoip_get_country_by_addr(&tar);
name = geoip_get_country_name(country); name = geoip_get_country_name(country);
return smartlist_string_isin_case(cc_list, name); return smartlist_contains_string_case(cc_list, name);
} }
/** Return 1 if <b>addr</b>:<b>port</b> is permitted to publish to our /** Return 1 if <b>addr</b>:<b>port</b> is permitted to publish to our

View File

@ -931,7 +931,7 @@ rend_service_requires_uptime(rend_service_t *service)
for (i=0; i < smartlist_len(service->ports); ++i) { for (i=0; i < smartlist_len(service->ports); ++i) {
p = smartlist_get(service->ports, i); p = smartlist_get(service->ports, i);
if (smartlist_string_num_isin(get_options()->LongLivedPorts, if (smartlist_contains_int_as_string(get_options()->LongLivedPorts,
p->virtual_port)) p->virtual_port))
return 1; return 1;
} }
@ -2774,7 +2774,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
char *hs_dir_ip; char *hs_dir_ip;
const node_t *node; const node_t *node;
hs_dir = smartlist_get(responsible_dirs, j); hs_dir = smartlist_get(responsible_dirs, j);
if (smartlist_digest_isin(renddesc->successful_uploads, if (smartlist_contains_digest(renddesc->successful_uploads,
hs_dir->identity_digest)) hs_dir->identity_digest))
/* Don't upload descriptor if we succeeded in doing so last time. */ /* Don't upload descriptor if we succeeded in doing so last time. */
continue; continue;
@ -2809,7 +2809,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
hs_dir->or_port); hs_dir->or_port);
tor_free(hs_dir_ip); tor_free(hs_dir_ip);
/* Remember successful upload to this router for next time. */ /* Remember successful upload to this router for next time. */
if (!smartlist_digest_isin(successful_uploads, hs_dir->identity_digest)) if (!smartlist_contains_digest(successful_uploads, hs_dir->identity_digest))
smartlist_add(successful_uploads, hs_dir->identity_digest); smartlist_add(successful_uploads, hs_dir->identity_digest);
} }
smartlist_clear(responsible_dirs); smartlist_clear(responsible_dirs);
@ -2827,7 +2827,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
if (!renddesc->successful_uploads) if (!renddesc->successful_uploads)
renddesc->successful_uploads = smartlist_new(); renddesc->successful_uploads = smartlist_new();
SMARTLIST_FOREACH(successful_uploads, const char *, c, { SMARTLIST_FOREACH(successful_uploads, const char *, c, {
if (!smartlist_digest_isin(renddesc->successful_uploads, c)) { if (!smartlist_contains_digest(renddesc->successful_uploads, c)) {
char *hsdir_id = tor_memdup(c, DIGEST_LEN); char *hsdir_id = tor_memdup(c, DIGEST_LEN);
smartlist_add(renddesc->successful_uploads, hsdir_id); smartlist_add(renddesc->successful_uploads, hsdir_id);
} }

View File

@ -1858,7 +1858,7 @@ router_rebuild_descriptor(int force)
member = node_get_by_nickname(name, 1); member = node_get_by_nickname(name, 1);
if (!member) { if (!member) {
int is_legal = is_legal_nickname_or_hexdigest(name); int is_legal = is_legal_nickname_or_hexdigest(name);
if (!smartlist_string_isin(warned_nonexistent_family, name) && if (!smartlist_contains_string(warned_nonexistent_family, name) &&
!is_legal_hexdigest(name)) { !is_legal_hexdigest(name)) {
if (is_legal) if (is_legal)
log_warn(LD_CONFIG, log_warn(LD_CONFIG,
@ -1884,7 +1884,7 @@ router_rebuild_descriptor(int force)
base16_encode(fp+1,HEX_DIGEST_LEN+1, base16_encode(fp+1,HEX_DIGEST_LEN+1,
member->identity, DIGEST_LEN); member->identity, DIGEST_LEN);
smartlist_add(ri->declared_family, fp); smartlist_add(ri->declared_family, fp);
if (smartlist_string_isin(warned_nonexistent_family, name)) if (smartlist_contains_string(warned_nonexistent_family, name))
smartlist_string_remove(warned_nonexistent_family, name); smartlist_string_remove(warned_nonexistent_family, name);
} }
skip: skip:

View File

@ -541,7 +541,7 @@ authority_certs_fetch_missing(networkstatus_t *status, time_t now)
int found = 0; int found = 0;
if (!(ds->type & V3_DIRINFO)) if (!(ds->type & V3_DIRINFO))
continue; continue;
if (smartlist_digest_isin(missing_digests, ds->v3_identity_digest)) if (smartlist_contains_digest(missing_digests, ds->v3_identity_digest))
continue; continue;
cl = get_cert_list(ds->v3_identity_digest); cl = get_cert_list(ds->v3_identity_digest);
SMARTLIST_FOREACH(cl->certs, authority_cert_t *, cert, { SMARTLIST_FOREACH(cl->certs, authority_cert_t *, cert, {
@ -3327,7 +3327,7 @@ routerlist_remove_old_cached_routers_with_id(time_t now,
signed_descriptor_t *r_next; signed_descriptor_t *r_next;
lifespans[i-lo].idx = i; lifespans[i-lo].idx = i;
if (r->last_listed_as_valid_until >= now || if (r->last_listed_as_valid_until >= now ||
(retain && digestset_isin(retain, r->signed_descriptor_digest))) { (retain && digestset_contains(retain, r->signed_descriptor_digest))) {
must_keep[i-lo] = 1; must_keep[i-lo] = 1;
} }
if (i < hi) { if (i < hi) {
@ -3461,7 +3461,7 @@ routerlist_remove_old_routers(void)
router = smartlist_get(routerlist->routers, i); router = smartlist_get(routerlist->routers, i);
if (router->cache_info.published_on <= cutoff && if (router->cache_info.published_on <= cutoff &&
router->cache_info.last_listed_as_valid_until < now && router->cache_info.last_listed_as_valid_until < now &&
!digestset_isin(retain, !digestset_contains(retain,
router->cache_info.signed_descriptor_digest)) { router->cache_info.signed_descriptor_digest)) {
/* Too old: remove it. (If we're a cache, just move it into /* Too old: remove it. (If we're a cache, just move it into
* old_routers.) */ * old_routers.) */
@ -3482,7 +3482,7 @@ routerlist_remove_old_routers(void)
sd = smartlist_get(routerlist->old_routers, i); sd = smartlist_get(routerlist->old_routers, i);
if (sd->published_on <= cutoff && if (sd->published_on <= cutoff &&
sd->last_listed_as_valid_until < now && sd->last_listed_as_valid_until < now &&
!digestset_isin(retain, sd->signed_descriptor_digest)) { !digestset_contains(retain, sd->signed_descriptor_digest)) {
/* Too old. Remove it. */ /* Too old. Remove it. */
routerlist_remove_old(routerlist, sd, i--); routerlist_remove_old(routerlist, sd, i--);
} }
@ -3661,7 +3661,7 @@ router_load_routers_from_string(const char *s, const char *eos,
ri->cache_info.signed_descriptor_digest : ri->cache_info.signed_descriptor_digest :
ri->cache_info.identity_digest, ri->cache_info.identity_digest,
DIGEST_LEN); DIGEST_LEN);
if (smartlist_string_isin(requested_fingerprints, fp)) { if (smartlist_contains_string(requested_fingerprints, fp)) {
smartlist_string_remove(requested_fingerprints, fp); smartlist_string_remove(requested_fingerprints, fp);
} else { } else {
char *requested = char *requested =

View File

@ -428,7 +428,7 @@ static void
add_transport_to_proxy(const char *transport, managed_proxy_t *mp) add_transport_to_proxy(const char *transport, managed_proxy_t *mp)
{ {
tor_assert(mp->transports_to_launch); tor_assert(mp->transports_to_launch);
if (!smartlist_string_isin(mp->transports_to_launch, transport)) if (!smartlist_contains_string(mp->transports_to_launch, transport))
smartlist_add(mp->transports_to_launch, tor_strdup(transport)); smartlist_add(mp->transports_to_launch, tor_strdup(transport));
} }
@ -453,7 +453,7 @@ proxy_needs_restart(const managed_proxy_t *mp)
goto needs_restart; goto needs_restart;
SMARTLIST_FOREACH_BEGIN(mp->transports, const transport_t *, t) { SMARTLIST_FOREACH_BEGIN(mp->transports, const transport_t *, t) {
if (!smartlist_string_isin(mp->transports_to_launch, t->name)) if (!smartlist_contains_string(mp->transports_to_launch, t->name))
goto needs_restart; goto needs_restart;
} SMARTLIST_FOREACH_END(t); } SMARTLIST_FOREACH_END(t);

View File

@ -309,18 +309,18 @@ bench_dmap(void)
NANOCOUNT(pt3, pt4, iters*elts)); NANOCOUNT(pt3, pt4, iters*elts));
for (i = 0; i < iters; ++i) { for (i = 0; i < iters; ++i) {
SMARTLIST_FOREACH(sl, const char *, cp, n += digestset_isin(ds, cp)); SMARTLIST_FOREACH(sl, const char *, cp, n += digestset_contains(ds, cp));
SMARTLIST_FOREACH(sl2, const char *, cp, n += digestset_isin(ds, cp)); SMARTLIST_FOREACH(sl2, const char *, cp, n += digestset_contains(ds, cp));
} }
end = perftime(); end = perftime();
printf("digestset_isin: %.2f ns per element.\n", printf("digestset_contains: %.2f ns per element.\n",
NANOCOUNT(pt4, end, iters*elts*2)); NANOCOUNT(pt4, end, iters*elts*2));
/* We need to use this, or else the whole loop gets optimized out. */ /* We need to use this, or else the whole loop gets optimized out. */
printf("Hits == %d\n", n); printf("Hits == %d\n", n);
for (i = 0; i < fpostests; ++i) { for (i = 0; i < fpostests; ++i) {
crypto_rand(d, 20); crypto_rand(d, 20);
if (digestset_isin(ds, d)) ++fp; if (digestset_contains(ds, d)) ++fp;
} }
printf("False positive rate on digestset: %.2f%%\n", printf("False positive rate on digestset: %.2f%%\n",
(fp/(double)fpostests)*100); (fp/(double)fpostests)*100);

View File

@ -66,8 +66,8 @@ test_container_smartlist_basic(void)
test_eq(4, smartlist_len(sl)); test_eq(4, smartlist_len(sl));
/* test isin. */ /* test isin. */
test_assert(smartlist_isin(sl, (void*)3)); test_assert(smartlist_contains(sl, (void*)3));
test_assert(!smartlist_isin(sl, (void*)99)); test_assert(!smartlist_contains(sl, (void*)99));
done: done:
smartlist_free(sl); smartlist_free(sl);
@ -195,13 +195,13 @@ test_container_smartlist_strings(void)
tor_free(cp_alloc); tor_free(cp_alloc);
smartlist_shuffle(sl); smartlist_shuffle(sl);
test_eq(7, smartlist_len(sl)); test_eq(7, smartlist_len(sl));
test_assert(smartlist_string_isin(sl, "and")); test_assert(smartlist_contains_string(sl, "and"));
test_assert(smartlist_string_isin(sl, "router")); test_assert(smartlist_contains_string(sl, "router"));
test_assert(smartlist_string_isin(sl, "by")); test_assert(smartlist_contains_string(sl, "by"));
test_assert(smartlist_string_isin(sl, "nickm")); test_assert(smartlist_contains_string(sl, "nickm"));
test_assert(smartlist_string_isin(sl, "onion")); test_assert(smartlist_contains_string(sl, "onion"));
test_assert(smartlist_string_isin(sl, "arma")); test_assert(smartlist_contains_string(sl, "arma"));
test_assert(smartlist_string_isin(sl, "the")); test_assert(smartlist_contains_string(sl, "the"));
/* Test bsearch. */ /* Test bsearch. */
smartlist_sort(sl, compare_strs_); smartlist_sort(sl, compare_strs_);
@ -279,12 +279,12 @@ test_container_smartlist_strings(void)
tor_free(cp_alloc); tor_free(cp_alloc);
/* Test string_isin and isin_case and num_isin */ /* Test string_isin and isin_case and num_isin */
test_assert(smartlist_string_isin(sl, "noon")); test_assert(smartlist_contains_string(sl, "noon"));
test_assert(!smartlist_string_isin(sl, "noonoon")); test_assert(!smartlist_contains_string(sl, "noonoon"));
test_assert(smartlist_string_isin_case(sl, "nOOn")); test_assert(smartlist_contains_string_case(sl, "nOOn"));
test_assert(!smartlist_string_isin_case(sl, "nooNooN")); test_assert(!smartlist_contains_string_case(sl, "nooNooN"));
test_assert(smartlist_string_num_isin(sl, 50)); test_assert(smartlist_contains_int_as_string(sl, 50));
test_assert(!smartlist_string_num_isin(sl, 60)); test_assert(!smartlist_contains_int_as_string(sl, 60));
/* Test smartlist_choose */ /* Test smartlist_choose */
{ {
@ -292,12 +292,12 @@ test_container_smartlist_strings(void)
int allsame = 1; int allsame = 1;
int allin = 1; int allin = 1;
void *first = smartlist_choose(sl); void *first = smartlist_choose(sl);
test_assert(smartlist_isin(sl, first)); test_assert(smartlist_contains(sl, first));
for (i = 0; i < 100; ++i) { for (i = 0; i < 100; ++i) {
void *second = smartlist_choose(sl); void *second = smartlist_choose(sl);
if (second != first) if (second != first)
allsame = 0; allsame = 0;
if (!smartlist_isin(sl, second)) if (!smartlist_contains(sl, second))
allin = 0; allin = 0;
} }
test_assert(!allsame); test_assert(!allsame);
@ -365,15 +365,15 @@ test_container_smartlist_overlap(void)
smartlist_add_all(sl, odds); smartlist_add_all(sl, odds);
smartlist_intersect(sl, primes); smartlist_intersect(sl, primes);
test_eq(smartlist_len(sl), 3); test_eq(smartlist_len(sl), 3);
test_assert(smartlist_isin(sl, (void*)3)); test_assert(smartlist_contains(sl, (void*)3));
test_assert(smartlist_isin(sl, (void*)5)); test_assert(smartlist_contains(sl, (void*)5));
test_assert(smartlist_isin(sl, (void*)7)); test_assert(smartlist_contains(sl, (void*)7));
/* subtract */ /* subtract */
smartlist_add_all(sl, primes); smartlist_add_all(sl, primes);
smartlist_subtract(sl, odds); smartlist_subtract(sl, odds);
test_eq(smartlist_len(sl), 1); test_eq(smartlist_len(sl), 1);
test_assert(smartlist_isin(sl, (void*)2)); test_assert(smartlist_contains(sl, (void*)2));
done: done:
smartlist_free(odds); smartlist_free(odds);
@ -393,10 +393,10 @@ test_container_smartlist_digests(void)
smartlist_add(sl, tor_memdup("AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN)); smartlist_add(sl, tor_memdup("AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN)); smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN)); smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
test_eq(0, smartlist_digest_isin(NULL, "AAAAAAAAAAAAAAAAAAAA")); test_eq(0, smartlist_contains_digest(NULL, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_digest_isin(sl, "AAAAAAAAAAAAAAAAAAAA")); test_assert(smartlist_contains_digest(sl, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_digest_isin(sl, "\00090AAB2AAAAaasdAAAAA")); test_assert(smartlist_contains_digest(sl, "\00090AAB2AAAAaasdAAAAA"));
test_eq(0, smartlist_digest_isin(sl, "\00090AAB2AAABaasdAAAAA")); test_eq(0, smartlist_contains_digest(sl, "\00090AAB2AAABaasdAAAAA"));
/* sort digests */ /* sort digests */
smartlist_sort_digests(sl); smartlist_sort_digests(sl);
@ -445,11 +445,11 @@ test_container_smartlist_join(void)
} SMARTLIST_FOREACH_JOIN_END(cp1, cp2); } SMARTLIST_FOREACH_JOIN_END(cp1, cp2);
SMARTLIST_FOREACH(sl3, const char *, cp, SMARTLIST_FOREACH(sl3, const char *, cp,
test_assert(smartlist_isin(sl2, cp) && test_assert(smartlist_contains(sl2, cp) &&
!smartlist_string_isin(sl, cp))); !smartlist_contains_string(sl, cp)));
SMARTLIST_FOREACH(sl4, const char *, cp, SMARTLIST_FOREACH(sl4, const char *, cp,
test_assert(smartlist_isin(sl, cp) && test_assert(smartlist_contains(sl, cp) &&
smartlist_string_isin(sl2, cp))); smartlist_contains_string(sl2, cp)));
joined = smartlist_join_strings(sl3, ",", 0, NULL); joined = smartlist_join_strings(sl3, ",", 0, NULL);
test_streq(joined, "Anemias,Anemias,Crossbowmen,Work"); test_streq(joined, "Anemias,Anemias,Crossbowmen,Work");
tor_free(joined); tor_free(joined);
@ -528,18 +528,18 @@ test_container_digestset(void)
} }
set = digestset_new(1000); set = digestset_new(1000);
SMARTLIST_FOREACH(included, const char *, cp, SMARTLIST_FOREACH(included, const char *, cp,
if (digestset_isin(set, cp)) if (digestset_contains(set, cp))
ok = 0); ok = 0);
test_assert(ok); test_assert(ok);
SMARTLIST_FOREACH(included, const char *, cp, SMARTLIST_FOREACH(included, const char *, cp,
digestset_add(set, cp)); digestset_add(set, cp));
SMARTLIST_FOREACH(included, const char *, cp, SMARTLIST_FOREACH(included, const char *, cp,
if (!digestset_isin(set, cp)) if (!digestset_contains(set, cp))
ok = 0); ok = 0);
test_assert(ok); test_assert(ok);
for (i = 0; i < 1000; ++i) { for (i = 0; i < 1000; ++i) {
crypto_rand(d, DIGEST_LEN); crypto_rand(d, DIGEST_LEN);
if (digestset_isin(set, d)) if (digestset_contains(set, d))
++false_positives; ++false_positives;
} }
test_assert(false_positives < 50); /* Should be far lower. */ test_assert(false_positives < 50); /* Should be far lower. */

View File

@ -2215,13 +2215,13 @@ test_util_listdir(void *ptr)
dir_contents = tor_listdir(dirname); dir_contents = tor_listdir(dirname);
test_assert(dir_contents); test_assert(dir_contents);
/* make sure that each filename is listed. */ /* make sure that each filename is listed. */
test_assert(smartlist_string_isin_case(dir_contents, "hopscotch")); test_assert(smartlist_contains_string_case(dir_contents, "hopscotch"));
test_assert(smartlist_string_isin_case(dir_contents, "mumblety-peg")); test_assert(smartlist_contains_string_case(dir_contents, "mumblety-peg"));
test_assert(smartlist_string_isin_case(dir_contents, ".hidden-file")); test_assert(smartlist_contains_string_case(dir_contents, ".hidden-file"));
test_assert(smartlist_string_isin_case(dir_contents, "some-directory")); test_assert(smartlist_contains_string_case(dir_contents, "some-directory"));
test_assert(!smartlist_string_isin(dir_contents, ".")); test_assert(!smartlist_contains_string(dir_contents, "."));
test_assert(!smartlist_string_isin(dir_contents, "..")); test_assert(!smartlist_contains_string(dir_contents, ".."));
done: done:
tor_free(fname1); tor_free(fname1);