Git Product home page Git Product logo

c-hashmap's Introduction

hashmap

基于C11实现的hashmap, 使用链表解决冲突。

API

初始化和销毁

HashMap map = createHashMap();

deleteHashMap(&map);

插入、取值和删除

// 插入, key为string, value支持任意类型
map->set(map, "hello", "world");
int number = 65535;
map->set(map, "number", &number);

// 取值
char *val1 = (char *)map->get(map, "hello");
int val2 = *(int *)map->get(map, "number");
bool hasVal = map->has(map, "hello"); // true

// 删除
map->delete(map, "hello");

// 删除所有
map->clear(map);

迭代器

// 创建
HashMapIterator iterator = createHashMapIterator(map);

// 根据hashcode的顺序进行迭代
while (iterator->hasNext(iterator)) {
    iterator = iterator->next(iterator);
    char *key = (char *)iterator->node->key;
    char *value = (char *)iterator->node->value;
}

// 销毁
deleteHashMapIterator(&iterator);

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.