CEntry* cachelookup(Cache *c, char *name, int create) { int h; CEntry *e; h = hash(name) % c->nhash; for(e=c->hash[h]; e; e=e->hash.next){ if(strcmp(name, e->name) == 0){ movetofront(c, e); return e; } } if(!create) return nil; if(c->nentry >= c->maxentry) e = evict(c); else{ e = emalloc(c->sizeofentry); insertfront(c, e); c->nentry++; } e->name = estrdup(name); h = hash(name) % c->nhash; e->hash.next = c->hash[h]; c->hash[h] = e; return e; }
struct node * numberToLinkedList(int N) { int a[100], temp = 0,i=0,j=0; struct node* first; first = NULL; if (N < 0) { N = N*-1; } if (N == 0) { first = insert(first, N); return first; } if (N > 0) { while (N != 0) { temp = N % 10; a[i] = temp; N = N / 10; i++; } for (j = 0; j < i; j++) { first = insertfront(first, a[j]); } return first; } }
int main(){ node y; node z; y.x = 1; y.next = &z; z.x = 2; z.next = NULL; node *y1 = &y; y1=insertfront(y1,4); print_list(y1); node *z1; z1=insertfront(z1,902); z1=insertfront(z1,66); z1=insertfront(z1,78); print_list(z1); free_list(z1); printf("printing out freed z1 list.... -> random numbers returned\n"); print_list(z1); }
static CEntry* evict(Cache *c) { CEntry *e; e = c->tail; popout(c, e); c->cefree(e); free(e->name); e->name = nil; memset(e, 0, c->sizeofentry); insertfront(c, e); return e; }
static void movetofront(Cache *c, CEntry *e) { popout(c, e); insertfront(c, e); }