• Stars
    star
    6
  • Rank 2,539,965 (Top 51 %)
  • Language
    C
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 1 year 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,813
star
2

cebsocket

Lightweight WebSocket library for C.
C
85
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

GodotCarouselMenu

Horizontal carousel menu for Godot 4
GDScript
13
star
8

vegetables

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

MoneroSharp

Monero library for C#
C#
12
star
10

react-kitten

React desktop environment for the web. React-ish and highly customizable. ๐Ÿฑ
TypeScript
9
star
11

jquery.datepicker

โŒš a futuristic datepicker for web
JavaScript
9
star
12

node-Win32Volume

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

json-tcp-socket

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

pokerunicorn-server

PokerUnicorn Server
C
3
star
15

BigCat

Big number library for Godot Engine (GDScript)
GDScript
3
star
16

3DAudioVisualization

3D audio visualization thing in Godot Engine
GDScript
3
star
17

python-jsonic

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

GodotBorderRadius

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

CatPong

Low-level multiplayer pong game with pure TCP protocol and SDL2 graphics for the Cat tutorial on meowingcat.io.
C
2
star
20

snake

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

meow

Quick screen recorder to GIF
JavaScript
2
star
22

HexBinDecConverter

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

semserv

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

WinDrag

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

catcrypt

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

sound-level-protect

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