int newoffset=tailoffset+4;
struct ListNode *ptr=tail;
if (newoffset>=WLISTSIZE) {
- newoffset-=WLISTSIZE;
- struct ListNode *oldptr=ptr;
- ptr=ptr->next;
- free(oldptr);
+ if (newoffset!=WLISTSIZE||head!=tail) {
+ newoffset-=WLISTSIZE;
+ struct ListNode *oldptr=ptr;
+ ptr=ptr->next;
+ free(oldptr);
+ }
}
tail=ptr;
tailoffset=newoffset;
if (headoffset==WLISTSIZE) {
if (head->next==0) {
head->next=(struct ListNode *)malloc(sizeof(struct ListNode));
- head->next=0;
+ head->next->next=0;
}
headoffset=0;
head=head->next;
+ if (tailoffset==WLISTSIZE) { /* roll the tail over also */
+ tailoffset=0;
+ tail=tail->next;
+ }
}
head->data[headoffset++]=id;
head->data[headoffset++]=type;
}
SimpleHash * SimpleHash::imageSet(int key) {
- SimpleHash * newset=new SimpleHash(count(key));
+ SimpleHash * newset=new SimpleHash(2*count(key)+4);
unsigned int hashkey = (unsigned int)key % size;
struct SimpleNode *ptr = bucket[hashkey];