Git Product home page Git Product logo

hashmap's Introduction

hashmap

一个基于redis中字典类型封装得来的hashmap (稍稍改了点 emmm...)

键类型为字符串

值类型可以为字符串 整数 浮点数 指针

Example

#include <stdio.h>
#include "hashmap.h"

void test(HashMap mm)
{
    hm_set(mm, "QQQ", 22, int32);
}

int main()
{
    HashMap mm = hm_init();
    hm_set(mm, "QAQ", 3.14, double);
    hm_get(mm, "QAQ", double);
    hm_update(mm, "QAQ", 6.28, double);
    hm_get(mm, "QAQ", double);
    
    hm_set(mm, "QWQ", "hello world", HM_STR);
    printf("%s\n", hm_get(mm, "QWQ", HM_STR));

    test(mm);
    printf("%d\n", hm_get(mm, "QQQ", int32));

    hm_release(mm);
    return 0;
}

详见test.c

API

预定义类型宏(value支持类型)

  • hm_ptr 指针

  • hm_str 字符串

  • int32 32位有符号整数

  • uint32 32位无符号整数

  • int64 64位有符号整数

  • uint64 64位无符号整数

  • double 双精度浮点型

HashMap

哈希表指针类型

hm_init()

返回值 => 哈希表指针

hm_set(哈希表指针, 键(字符串类型), 值, 值的类型)

返回值 => 0:插入成功 1:插入失败

hm_get(哈希表指针, 键(字符串类型), 值)

返回值 => 值(若为字符串返回的是指针)

当get键不存在时 对于指针类型返回NULL 其他返回类型最大值

hm_update(哈希表指针, 键(字符串类型), 新的值, 值的类型)

返回值 => 0:插入成功 1:插入失败

hm_del(哈希表指针, 键(字符串类型))

返回值 => 无

Usage

gcc yourfile.c hashmap.c dict.c or g++ yourfile.c hashmap.c dict.c

hashmap's People

Contributors

userpro avatar

Watchers

 avatar  avatar

Forkers

jjzhang166

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.