c语言中的hashmap

定义

c 复制代码
struct hashTable {
    int key;
    int val;
    UT_hash_handle hh;
};

struct hashTable* hashtable;

struct hashTable* find(int ikey) {
    struct hashTable* tmp;
    HASH_FIND_INT(hashtable, &ikey, tmp);
    return tmp;
}

void insert(int ikey, int ival) {
    struct hashTable* it = find(ikey);
    if (it == NULL) {
        struct hashTable* tmp = malloc(sizeof(struct hashTable));
        tmp->key = ikey, tmp->val = ival;
        HASH_ADD_INT(hashtable, key, tmp);
    } else {
        it->val = ival;
    }
}

使用

c 复制代码
hashtable = NULL;
struct hashTable* it = find(target - nums[i]);
insert(nums[i], i);
相关推荐
q5431470875 分钟前
VScode 开发 Springboot 程序
java·spring boot·后端
小白自救计划6 分钟前
力扣知识点杂集
算法·leetcode·哈希算法
小涛不学习14 分钟前
Java高频面试题(带答案版)
java·开发语言
big_rabbit050214 分钟前
JVM堆内存查看命令
java·linux·算法
承渊政道19 分钟前
【优选算法】(实战体验滑动窗口的奇妙之旅)
c语言·c++·笔记·学习·算法·leetcode·visual studio
学习要积极22 分钟前
Springboot图片验证码-EasyCaptcha
java·spring boot·后端
C羊驼33 分钟前
C语言学习笔记(十):操作符
c语言·开发语言·经验分享·笔记·学习
李少兄33 分钟前
企业资源计划(ERP)系统全景指南
java·前端·数据库·erp
波波七36 分钟前
SSM与Springboot是什么关系? -----区别与联系
java·spring boot·后端
myloveasuka37 分钟前
[Java]单列集合
android·java·开发语言