int listsetlength(List* l, unsigned long sz) { if(l == NULL) return FALSE; if(sz > l->alloc && !listsetalloc(l,sz)) return FALSE; l->length = sz; return TRUE; }
int listsetlength(List* sq, unsigned int sz) { if(sq == NULL) return FALSE; if(!listsetalloc(sq,sz)) return FALSE; sq->length = sz; return TRUE; }
int listpush(List* l, void* elem) { if(l == NULL) return FALSE; if(l->length >= l->alloc) listsetalloc(l,0); l->content[l->length] = elem; l->length++; return TRUE; }
int listpush(List* sq, elem_t elem) { if(sq == NULL) return FALSE; if(sq->length >= sq->alloc) listsetalloc(sq,0); sq->content[sq->length] = elem; sq->length++; return TRUE; }
List* prefixdup(List* prefix) { List* dupseq; int i; if(prefix == NULL) return listnew(); dupseq = listnew(); listsetalloc(dupseq,listlength(prefix)); for(i=0;i<listlength(prefix);i++) listpush(dupseq,listget(prefix,i)); return dupseq; }
/* Insert at position i of l; will push up elements i..|seq|. */ int listinsert(List* l, unsigned long index, void* elem) { int i; /* do not make unsigned */ if(l == NULL) return FALSE; if(index > l->length) return FALSE; listsetalloc(l,0); for(i=(int)l->length;i>index;i--) l->content[i] = l->content[i-1]; l->content[index] = elem; l->length++; return TRUE; }
int listfpush(List* sq, elem_t elem) { unsigned int i; if(sq == NULL) return FALSE; if(sq->length >= sq->alloc) listsetalloc(sq,0); /* could we trust bcopy? instead */ for(i=sq->alloc;i>=1;i--) {sq->content[i]=sq->content[i-1];} sq->content[0] = elem; sq->length++; return TRUE; }
/* Insert at position i of sq; will push up elements i..|seq|. */ int listinsert(List* sq, unsigned int index, elem_t elem) { unsigned int i; if(sq == NULL) return FALSE; if(index > sq->length) return FALSE; listsetalloc(sq,0); for(i=sq->length;i>index;i--) sq->content[i] = sq->content[i-1]; sq->content[index] = elem; sq->length++; return TRUE; }