【Leet Code笔记】【C】hashmap初级使用

C中的hash map

由于C语言中没有提供官方的hash map支持,并且我的工作开发环境是基于linux的,所以我在做题时选用了uthash来进行。

uthash使用

1.导入
include<uthash.h>;
2.构建结构

struct hashTable{
	int key;
	int val;
	/*each struct map each kay-value;*/
	UT_hash_handle hh;// makes this structure hashable 
}

3.基本使用
初始化:

struct hashTable* urHashTable = NULL;

增:

void insert(int iKey, int iVal){ 
	struct hashTable* tmp = malloc(sizeof(struct hashTable));
    tmp -> key = iKey;
    tmp -> val = iVal;
    HASH_ADD_INT(urHashTable, data, tmp);
}

查:

struct hushTable* find(int iKey){
	struct hashTable* tmpFind;
	HASH_FIND_INT(urHashTable, &iKey, tmpFind);
	return tmpFind;
}

编译错误点:
1.runtime error: store to address 0x625000002048 with insufficient space for an object of type ‘unsigned int’

可能原因: malloc分配错误,在分配空间时写错。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值