// Returns reference if refmap contains a reference with matching // label, otherwise NULL. reference* reference_lookup(reference_map *map, chunk *label) { reference *ref = NULL; unsigned char *norm; unsigned int hash; if (map == NULL) return NULL; norm = normalize_reference(label); if (norm == NULL) return NULL; hash = refhash(norm); ref = map->table[hash % REFMAP_SIZE]; while (ref) { if (ref->hash == hash && !strcmp((char *)ref->label, (char *)norm)) break; ref = ref->next; } free(norm); return ref; }
// Returns reference if refmap contains a reference with matching // label, otherwise NULL. cmark_reference *cmark_reference_lookup(cmark_reference_map *map, cmark_chunk *label) { cmark_reference *ref = NULL; unsigned char *norm; unsigned int hash; if (label->len > MAX_LINK_LABEL_LENGTH) return NULL; if (map == NULL) return NULL; norm = normalize_reference(map->mem, label); if (norm == NULL) return NULL; hash = refhash(norm); ref = map->table[hash % REFMAP_SIZE]; while (ref) { if (ref->hash == hash && !strcmp((char *)ref->label, (char *)norm)) break; ref = ref->next; } free(norm); return ref; }
int naiHash_tryset(naRef hash, naRef key, naRef val) { HashRec* hr = REC(hash); if(hr) { int ent, cell = findcell(hr, key, refhash(key)); if((ent = TAB(hr)[cell]) >= 0) { ENTS(hr)[ent].val = val; return 1; } } return 0; }
int naHash_get(naRef hash, naRef key, naRef* out) { HashRec* hr = REC(hash); if(hr) { int ent, cell = findcell(hr, key, refhash(key)); if((ent = TAB(hr)[cell]) < 0) return 0; *out = ENTS(hr)[ent].val; return 1; } return 0; }
static void hashset(HashRec* hr, naRef key, naRef val) { int ent, cell = findcell(hr, key, refhash(key)); if((ent = TAB(hr)[cell]) == ENT_EMPTY) { ent = hr->next++; if(ent >= NCELLS(hr)) return; /* race protection, don't overrun */ TAB(hr)[cell] = ent; hr->size++; ENTS(hr)[ent].key = key; } ENTS(hr)[ent].val = val; }
void naHash_delete(naRef hash, naRef key) { HashRec* hr = REC(hash); if(hr) { int cell = findcell(hr, key, refhash(key)); if(TAB(hr)[cell] >= 0) { TAB(hr)[cell] = ENT_DELETED; if(--hr->size < POW2(hr->lgsz-1)) resize(PTR(hash).hash); } } }
void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, cmark_chunk *url, cmark_chunk *title) { cmark_reference *ref; unsigned char *reflabel = normalize_reference(map->mem, label); /* empty reference name, or composed from only whitespace */ if (reflabel == NULL) return; ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref)); ref->label = reflabel; ref->hash = refhash(ref->label); ref->url = cmark_clean_url(map->mem, url); ref->title = cmark_clean_title(map->mem, title); ref->next = NULL; add_reference(map, ref); }
extern void reference_create(reference_map *map, chunk *label, chunk *url, chunk *title) { reference *ref; unsigned char *reflabel = normalize_reference(label); /* empty reference name, or composed from only whitespace */ if (reflabel == NULL) return; ref = calloc(1, sizeof(*ref)); if(ref != NULL) { ref->label = reflabel; ref->hash = refhash(ref->label); ref->url = clean_url(url); ref->title = clean_title(title); ref->next = NULL; add_reference(map, ref); } }