unsigned int search_log(T value, Search type) { //Two different ways to search. The binary_search could // call expand_search anyway, but we'll save time and jump there // now if the conditions match. unsigned int lastIndex = lookup.size()-1; if (value>lookup[lastIndex]) { return expand_search(value, type, lastIndex); } else if (value>0) { return binary_search(value, type, 0, lastIndex); } else { return ~0; //Error } }
static struct node * map_search(struct map *m,struct key *key) { int i; size_t k=hash(m,key); struct node *temp=m->buffer+k; for (;;) { if (temp->value==0) { struct node *slot=temp; temp=temp->next; while (temp) { if (temp->key==key) { return temp; } temp=temp->next; } slot->key=key; return slot; } else if (temp->key==key) return temp; if (temp->next==0) { break; } temp=temp->next; } for (i=m->freenode;i<m->size;i++) { if (m->buffer[i].value==0) { m->buffer[i].key=key; temp->next=m->buffer+i; m->freenode=i+1; return &(m->buffer[i]); } } return expand_search(m,key); }