add_link_ref(
	struct link_ref **references,
	const uint8_t *name, size_t name_size)
{
	unsigned int hash;
	struct link_ref *ref;
	hash = hash_link_ref(name, name_size);
	ref = references[hash % REF_TABLE_SIZE];
	while (ref != NULL) {
		/* If a reference with the same label exists already, replace it with the new reference */
		if (ref->id == hash && ref->label->size == name_size) {
			if (strncasecmp((char *)ref->label->data, (char *) name, name_size) == 0) {
				bufrelease(ref->label);
				bufrelease(ref->link);
				bufrelease(ref->title);
				return ref;
			}
		}

		ref = ref->next;
	}
	ref = calloc(1, sizeof(struct link_ref));
	if (!ref)
		return NULL;
	ref->id = hash;
	ref->next = references[ref->id % REF_TABLE_SIZE];

	references[ref->id % REF_TABLE_SIZE] = ref;
	return ref;
}
add_link_ref(
	struct link_ref **references,
	const uint8_t *name, size_t name_size)
{
	unsigned int hash;
	struct link_ref *ref;
	hash = hash_link_ref(name, name_size);
	ref = references[hash % REF_TABLE_SIZE];
	while (ref != NULL) {
		 
		if (ref->id == hash && ref->label->size == name_size) {
			if (strncasecmp((char *)ref->label->data, (char *) name, name_size) == 0) {
				bufrelease(ref->label);
				bufrelease(ref->link);
				bufrelease(ref->title);
				return ref;
			}
		}

		ref = ref->next;
	}
	ref = calloc(1, sizeof(struct link_ref));
	if (!ref)
		return NULL;
	ref->id = hash;
	ref->next = references[ref->id % REF_TABLE_SIZE];

	references[ref->id % REF_TABLE_SIZE] = ref;
	return ref;
}