[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Put ourself in router list; act accordingly.
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv29684/src/common
Modified Files:
util.c util.h
Log Message:
Put ourself in router list; act accordingly.
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- util.c 6 Apr 2004 21:19:59 -0000 1.81
+++ util.c 7 Apr 2004 19:46:26 -0000 1.82
@@ -293,10 +293,39 @@
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
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- util.h 6 Apr 2004 21:19:59 -0000 1.53
+++ util.h 7 Apr 2004 19:46:26 -0000 1.54
@@ -113,6 +113,8 @@
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 { \