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);
相关推荐
tellmewhoisi15 分钟前
java8 List常用基本操作(去重,排序,转换等)
java·list
麦子邪40 分钟前
C语言中奇技淫巧04-仅对指定函数启用编译优化
linux·c语言·开发语言
都叫我大帅哥1 小时前
TOGAF应用架构阶段全解析:从理论到Java代码实战
java
Amagi.1 小时前
Java设计模式-建造者模式
java·设计模式·建造者模式
华强笔记1 小时前
C程序内存布局详解
服务器·c语言
EmpressBoost1 小时前
谷粒商城170缓存序列化报错
java·spring·缓存
fouryears_234171 小时前
@PathVariable与@RequestParam的区别
java·spring·mvc·springboot
程序员编程指南1 小时前
Qt OpenGL 集成:开发 3D 图形应用
c语言·数据库·c++·qt·3d
wxjlkh1 小时前
powershell 批量测试ip 端口 脚本
java·服务器·前端
萌新小白的逆袭2 小时前
《Maven 核心基础笔记(第一天)》
java·开发语言·spring