From a0e015b98f58f9edf5ce4f40bc3ac5a46e228dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 27 Oct 2005 11:58:10 +0000 Subject: when we add an item at a certain index that exceeds the number of elements, we resize the array to be able to hold the new index. use of "verbose()" svn path=/trunk/externals/zexy/; revision=3769 --- src/index.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/index.c') diff --git a/src/index.c b/src/index.c index 99ce4ae..51d19f4 100644 --- a/src/index.c +++ b/src/index.c @@ -126,11 +126,11 @@ static void index_add(t_index *x, t_symbol *s, t_float f) { int newentry=(int)f; int ok = 0; - + if (! (find_item(s, x->names, x->maxentries)+1) ) { - if (x->auto_resize && x->entries==x->maxentries){ + if (x->auto_resize && (x->entries==x->maxentries || newentry>=x->maxentries)){ /* do some resizing */ - int maxentries=x->maxentries*2; + int maxentries=(newentry>x->maxentries)?newentry:(x->maxentries*2); int i; t_symbol**buf=(t_symbol **)getbytes(sizeof(t_symbol *) * maxentries); if(buf!=0){ @@ -148,24 +148,22 @@ static void index_add(t_index *x, t_symbol *s, t_float f) if(newentry>0){ newentry--; if(x->names[newentry]){ /* it is already taken! */ - error("index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1); + verbose(1, "index :: couldn't add element '%s' at position %d (already taken)", s->s_name, newentry+1); outlet_float(x->x_obj.ob_outlet, -1.f); return; } - } else + } else { newentry=find_free(x->names, x->maxentries); - + } if (newentry + 1) { x->entries++; x->names[newentry]=s; - outlet_float(x->x_obj.ob_outlet, (t_float)newentry+1); return; } else error("index :: couldn't find any place for new entry"); } else error("index :: max number of elements (%d) reached !", x->maxentries); - } else post("index :: element '%s' already exists", s->s_name); - + } else verbose(1, "index :: element '%s' already exists", s->s_name); /* couldn't add the symbol to our index table */ outlet_float(x->x_obj.ob_outlet, -1.f); } @@ -192,7 +190,7 @@ static void index_delete(t_index *x, t_symbol *s, int argc, t_atom*argv) x->entries--; outlet_float(x->x_obj.ob_outlet, 0.0); } else { - post("index :: couldn't find element"); + verbose(1, "index :: couldn't find element"); outlet_float(x->x_obj.ob_outlet, -1.0); } } @@ -222,7 +220,6 @@ static void index_dump(t_index *x) { t_atom ap[2]; int i=0; - for(i=0; imaxentries; i++){ if(x->names[i]){ SETSYMBOL(ap, x->names[i]); -- cgit v1.2.1