• Stars
    star
    6
  • Rank 2,464,123 (Top 50 %)
  • Language
    C
  • License
    MIT License
  • Created over 2 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fast and efficient non-iterating hashmap library

libhash: a fast and efficient non-iterating hashmap library

Libhash is a fast and efficient non-iterating hashmap library

Usage

Usage is easy and simple. You can look to examples/ directory. You can build examples with make command.

Including

#include "libhash/include/libhash.h"

Building with source

gcc -o application libhash/src/libhash.c application.c

Linking libhash.o

Build libhash:

make

and use libhash.o:

gcc -o application application.c libhash/libhash.o

Simple Hashmap

Here is an example for simple hashmap.

#include <stdio.h>

#include "libhash/include/libhash.h"

int main() {
    libhash_t* movies = libhash_init();
    libhash_set(movies, "Alien", "The best movie ever!");
    libhash_set(movies, "Prometheus", "The worst movie ever!");
    libhash_set(movies, "γ“γ‚“γ«γ‘γ―δΈ–η•Œ", "Hello World!");

    libhash_node_t* alien = libhash_get(movies, "Alien");
    libhash_node_t* prometheus = libhash_get(movies, "Prometheus");
    libhash_node_t* hello = libhash_get(movies, "γ“γ‚“γ«γ‘γ―δΈ–η•Œ");

    hello && printf("γ“γ‚“γ«γ‘γ―δΈ–η•Œ: %s\n", hello->value);
    alien && printf("Alien: %s\n", alien->value);
    prometheus && printf("Prometheus: %s\n", prometheus->value);

    libhash_free(movies);

    return 0;
}

Hash Algorithm

It hashes NULL-terminated strings (I was lazy for making another binary one that works with length lol...) to 32-bit unsigned scalars.

I made some tests about conflictions and it looked oki. And I just made this hash algorithm in a coffee break and note sure how decent it is.

UTF-8 Support

Since I added hashing feature it always uses unsigned char indexes and support UTF-8.

Benchmark

There is a benchmark in examples/benchmark directory. You can just do:

cd examples/benchmark
make clean; make; ./benchmark

Functions

libhash_t* libhash_init()

Creates a hashmap.

libhash_node_t* libhash_set(libhash_t* hashmap, char* key, void* value)

Sets a key-value pair and returns the node.

void libhash_unset(libhash_t* hashmap, char* key)

Unsets a key-value pair.

libhash_node_t* libhash_get(libhash_t* hashmap, char* key)

Gets the value of key.

void libhash_free(libhash_t* hashmap)

Frees hashmap.

void libhash_node_free(libhash_node_t* node)

Frees node.

uint32_t libhash_hash32(char* str)

Accepts NULL-terminated string and returns a 32-bit unsigned scalar hash.

Types

libhash_t

The hashmap type.

typedef struct libhash libhash_t;
struct libhash {
    libhash_node_t* root;
};

libhash_node_t

typedef struct libhash_node libhash_node_t;
struct libhash_node {
    libhash_node_t* map[256];
    libhash_node_t* parent;
    void* value;
    int len;
};

License

Copyright (c) 2021 Oğuzhan Eroğlu [email protected] (https://oguzhaneroglu.com). All rights reserved.

This work is licensed under the terms of the MIT license.
For a copy, see https://opensource.org/licenses/MIT.

More Repositories

1

gdb-frontend

β˜• GDBFrontend is an easy, flexible and extensible gui debugger. Try it on https://debugme.dev
JavaScript
2,738
star
2

cebsocket

Lightweight WebSocket library for C.
C
84
star
3

nodes.js

🌌 nodes.js is a nodes/particles animation useable for backgrounds
JavaScript
27
star
4

gdb-frontend-live

GDBFrontendLive is a server that creates GDBFrontend instances and provides online sharable IDEs for each individiual users. πŸ›ΈπŸ‘½πŸŒŒ
C
24
star
5

jsonic

β­• Tricky, super fast and dumb JSON library for C/C++
C
20
star
6

virtual-joystick

Virtual Joystick plugin for Godot Engine
GDScript
13
star
7

MoneroSharp

Monero library for C#
C#
13
star
8

vegetables

Multiplayer deathmatch shooter game with cute vegetable characters.
GDScript
12
star
9

jquery.datepicker

⌚ a futuristic datepicker for web
JavaScript
9
star
10

GodotCarouselMenu

Horizontal carousel menu for Godot 4
GDScript
6
star
11

node-Win32Volume

Node.js, set volume level or mute functions for Win32 platform.
C++
4
star
12

json-tcp-socket

JSON messaging over TCP sockets for Node.js
JavaScript
3
star
13

python-jsonic

Python bindings for Jsonic JSON reader library.
C
2
star
14

snake

Snake is a snake game implementation on HTML5.
JavaScript
2
star
15

meow

Quick screen recorder to GIF
JavaScript
2
star
16

HexBinDecConverter

Hexadecimal, Binary and Decimal number converter plugin for Sublime Text 3
Python
1
star
17

3DAudioVisualization

3D audio visualization thing in Godot Engine
GDScript
1
star
18

GodotBorderRadius

Pixel-sized border radius shader for Godot 4
GDScript
1
star
19

WinDrag

Linux Desktop Environments-Like Alt+Drag Window Mover for Windows
C#
1
star
20

semserv

High-performance async semaphore service useable with long string ipc keys stored in memory.
C
1
star
21

catcrypt

Simple RSA public key encryption library for C/C++.
C
1
star
22

sound-level-protect

Maximum sound level protection for headphones on Win32 platform.
C++
1
star