aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-07 19:46:27 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-07 19:46:27 +0000
commit75c19716a80a96a7550dd723aca73c245987b87f (patch)
tree1ec9949a29f0fb47075037eff45d428dc5b9d062 /src/common
parent4a9587a486e35ea71aabe8391b05ceee22f2cd91 (diff)
downloadtor-75c19716a80a96a7550dd723aca73c245987b87f.tar.gz
tor-75c19716a80a96a7550dd723aca73c245987b87f.zip
Put ourself in router list; act accordingly.
svn:r1521
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c29
-rw-r--r--src/common/util.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 6df6853aba..f91d2ce061 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -293,10 +293,39 @@ void *smartlist_del(smartlist_t *sl, int idx)
sl->list[idx] = sl->list[--sl->num_used];
return old;
}
+void *smartlist_del_keeporder(smartlist_t *sl, int idx)
+{
+ void *old;
+ assert(sl && idx>=0 && idx < sl->num_used);
+ old = sl->list[idx];
+ --sl->num_used;
+ if (idx < sl->num_used)
+ memmove(sl->list+idx, sl->list+idx+1, sizeof(void*)*(sl->num_used-idx));
+ return old;
+}
int smartlist_len(smartlist_t *sl)
{
return sl->num_used;
}
+void smartlist_insert(smartlist_t *sl, int idx, void *val)
+{
+ assert(sl && idx >= 0 && idx <= sl->num_used);
+ if (idx == sl->num_used) {
+ smartlist_add(sl, val);
+ } else {
+ /* Ensure sufficient capacity */
+ if (sl->num_used >= sl->capacity) {
+ sl->capacity *= 2;
+ sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
+ }
+ /* Move other elements away */
+ if (idx < sl->num_used)
+ memmove(sl->list + idx + 1, sl->list + idx,
+ sizeof(void*)*(sl->num_used-idx));
+ sl->num_used++;
+ sl->list[idx] = val;
+ }
+}
/*
* Splay-tree implementation of string-to-void* map
diff --git a/src/common/util.h b/src/common/util.h
index 0500b1fe1c..763de87952 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -113,6 +113,8 @@ void *smartlist_choose(smartlist_t *sl);
void *smartlist_get(smartlist_t *sl, int idx);
void *smartlist_set(smartlist_t *sl, int idx, void *val);
void *smartlist_del(smartlist_t *sl, int idx);
+void *smartlist_del_keeporder(smartlist_t *sl, int idx);
+void smartlist_insert(smartlist_t *sl, int idx, void *val);
int smartlist_len(smartlist_t *sl);
#define SMARTLIST_FOREACH(sl, type, var, cmd) \
do { \