long ssdtableUpdate(DespTag tag, unsigned long hash_code, long despId)
{
	if (DEBUG)
		printf("[INFO] Insert tag: %lu, hash_code=%lu\n",tag.offset, hash_code);
	SSDHashBucket* nowbucket = GetSSDHashBucket(hash_code);
	SSDHashBucket* lastbucket = nowbucket;
	while (nowbucket != NULL) {
        lastbucket = nowbucket;
        if (IsSame(nowbucket->hash_key,tag)) {
            long oldId = nowbucket->despId;
            nowbucket->despId = despId;
            return oldId;
		}
		nowbucket = nowbucket->next_item;
	}

	// if not exist in table, insert one.

    SSDHashBucket* newitem = memPop();
    newitem->hash_key = tag;
    newitem->despId = despId;
    newitem->next_item = NULL;
    lastbucket->next_item = newitem;
	return -1;
}
Esempio n. 2
0
long ssdtableDelete(SSDTag *ssd_tag, unsigned long hash_code)
{
	if (DEBUG)
		printf("[INFO] Delete ssd_tag: %lu, hash_code=%lu\n",ssd_tag->offset, hash_code);
	SSDHashBucket *nowbucket = GetSSDHashBucket(hash_code);
	long del_id;
	SSDHashBucket *delitem;
	nowbucket->next_item;
	while (nowbucket->next_item != NULL && nowbucket != NULL) {
		if (isSamessd(&nowbucket->next_item->hash_key, ssd_tag)) {
			del_id = nowbucket->next_item->ssd_id;
			break;
		}
		nowbucket = nowbucket->next_item;
	}
	//printf("not found2\n");
	if (isSamessd(&nowbucket->hash_key, ssd_tag)) {
		del_id = nowbucket->ssd_id;
	}
	//printf("not found3\n");
	if (nowbucket->next_item != NULL) {
		delitem = nowbucket->next_item;
		nowbucket->next_item = nowbucket->next_item->next_item;
		free(delitem);
		return del_id;
	}
	else {
		delitem = nowbucket->next_item;
		nowbucket->next_item = NULL;
		free(delitem);
		return del_id;
	}

	return -1;
}
Esempio n. 3
0
long ssdtableInsert(SSDTag *ssd_tag, unsigned long hash_code, long ssd_id)
{
	if (DEBUG)
		printf("[INFO] Insert ssd_tag: %lu, hash_code=%lu\n",ssd_tag->offset, hash_code);
	SSDHashBucket *nowbucket = GetSSDHashBucket(hash_code);
	while (nowbucket->next_item != NULL && nowbucket != NULL) {
		if (isSamessd(&nowbucket->hash_key, ssd_tag)) {
			return nowbucket->ssd_id;
		}
		nowbucket = nowbucket->next_item;
	}
	if (nowbucket != NULL) {
		SSDHashBucket *newitem = (SSDHashBucket*)malloc(sizeof(SSDHashBucket));
		newitem->hash_key = *ssd_tag;
		newitem->ssd_id = ssd_id;
		newitem->next_item = NULL;
		nowbucket->next_item = newitem;
	}
	else {
		nowbucket->hash_key = *ssd_tag;
		nowbucket->ssd_id = ssd_id;
		nowbucket->next_item = NULL;
	}

	return -1;
}
long ssdtableInsert(DespTag tag, unsigned long hash_code, long despId)
{
	if (DEBUG)
		printf("[INFO] Insert tag: %lu, hash_code=%lu\n",tag.offset, hash_code);
	SSDHashBucket *nowbucket = GetSSDHashBucket(hash_code);
	while (nowbucket->next_item != NULL) {
		nowbucket = nowbucket->next_item;
	}

    SSDHashBucket* newitem = memPop();
    newitem->hash_key = tag;
    newitem->despId = despId;
    newitem->next_item = NULL;
    nowbucket->next_item = newitem;

	return 0;
}
long ssdtableLookup(DespTag tag, unsigned long hash_code)
{
	if (DEBUG)
		printf("[INFO] Lookup tag: %lu\n",tag.offset);
	SSDHashBucket *nowbucket = GetSSDHashBucket(hash_code);
	while (nowbucket != NULL) {
	//	printf("nowbucket->buf_id = %u %u %u\n", nowbucket->hash_key.rel.database, nowbucket->hash_key.rel.relation, nowbucket->hash_key.block_num);
		if (IsSame(nowbucket->hash_key, tag)) {
	//		printf("find\n");
			return nowbucket->despId;
		}
		nowbucket = nowbucket->next_item;
	}
//	printf("no find\n");

	return -1;
}
long ssdtableDelete(DespTag tag, unsigned long hash_code)
{
	if (DEBUG)
		printf("[INFO] Delete tag: %lu, hash_code=%lu\n",tag.offset, hash_code);
	SSDHashBucket *nowbucket = GetSSDHashBucket(hash_code);
	long del_id;
	SSDHashBucket *delitem;

	while (nowbucket->next_item != NULL) {
		if (IsSame(nowbucket->next_item->hash_key, tag)) {
            delitem = nowbucket->next_item;
            del_id = delitem->despId;
            nowbucket->next_item = delitem->next_item;
            memPush(delitem);
            return del_id;
		}
		nowbucket = nowbucket->next_item;
	}

	return -1;
}