{"id":21735020,"url":"https://github.com/janinawibker/alt-stdlib","last_synced_at":"2026-05-20T14:15:29.573Z","repository":{"id":91736928,"uuid":"365618276","full_name":"JaninaWibker/alt-stdlib","owner":"JaninaWibker","description":"An alternative to the standard library data structures and some other utilities for C++","archived":false,"fork":false,"pushed_at":"2025-03-14T17:18:31.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T18:37:18.967Z","etag":null,"topics":["alternative","c","cpp","standard-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JaninaWibker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-05-08T21:55:54.000Z","updated_at":"2025-03-14T17:18:35.000Z","dependencies_parsed_at":"2024-03-23T14:47:00.001Z","dependency_job_id":null,"html_url":"https://github.com/JaninaWibker/alt-stdlib","commit_stats":null,"previous_names":["janinawibker/alt-stdlib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaninaWibker%2Falt-stdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaninaWibker%2Falt-stdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaninaWibker%2Falt-stdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JaninaWibker%2Falt-stdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JaninaWibker","download_url":"https://codeload.github.com/JaninaWibker/alt-stdlib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244712552,"owners_count":20497502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alternative","c","cpp","standard-library"],"created_at":"2024-11-26T05:11:40.097Z","updated_at":"2026-05-20T14:15:24.553Z","avatar_url":"https://github.com/JaninaWibker.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# alternative stdlib\n\n\u003e **WIP**\n\nThis is intended to be a replacement for some of the standard library data structures as well as (maybe) other utilities (such as optionals).\n\nThis project is heavily inspired by [stb](https://github.com/nothings/stb), [serenityOS](https://github.com/SerenityOS/serenity), my operating systems and my algorithms class at university.\n\nIncluded data structures:\n- [unbounded array](#unbounded-array)\n- [hashtable](#hashtable)\n- [hashmap](#hashmap)\n- [minheap](#minheap)\n- [unionfind](#unionfind)\n\n## building and running tests\n\nUnit tests exist (for almost all data structures) and can be compiled using the `./build.sh`-file.\nThis is only a minimal wrapper around G++ (or rather `$CXX`), nothing complicated is done there.\n\n\u003e There will be a lot of warnings because the coding style is more c-like than normal c++, I'll maybe fix this in the future.\n\nThe resulting `test` executable can be run and will print the output of the unit tests, the first failing test halts the program.\n\n## components\n\n### (unbounded) array\n\nAn unbounded array implementation with a growth factor of 2.\n\n\u003e *TODO*\n\n\n### hashtable\n\nA hashtable implementation based on a unique technique taking inspiration from both doubly-linked lists and linear probing.\n\n\u003e The hashtable uses doubly-linked lists for saving values with hashes that clash but instead of allocating these elements randomly using malloc this is done manually.\n\u003e The twist is that all elements are allocated inside of the hashtable itself using a freelist which also spans across the hashtable containing all currently free \"slots\"\n\u003e Whenever a slot needs to be used it is unhooked from the freelist; whenever a slot is free'd it is returned to the freelist\n\n**hashtableinit**: Create a new hashtable\n\nCreate a new hashtable using an initial capacity and a given hash function\nUse as follows (`[x]` marks things to replace):\n```c\nauto hash = []([your type] x) -\u003e int { [your hash implementation] };\nauto ht = hashtableinit\u003c[your type], decltype(hash)\u003e([initial capacity], hash);\n```\n\n`hashtable\u003cT, H\u003e hashtableinit(size_t capacity, H hash)`\n\n\n**hashtablefree**: Free hashtable\n\n`void hashtablefree(hashtable\u003cT, H\u003e* ht)`\n\n\n**::resize**: Resize the hashtable\n\nThis can be called manually but will also be called internally whenever needed.\nIt might be useful to call this if you already know that you'll add a specific amount of items soon.\n\n`void hashtable\u003cT, H\u003e::resize(size_t new_size)`\n\n\n**::dbg**: Print debug information about the state of the hashtable\n\n`void hashtable\u003cT, H\u003e::dbg()`\n\n\n**::dbg**: Print debug information about the state of the hashtable\n\nIncludes a name which will be displayed alongside the debug information to tell debug logs apart.\n\n`void hashtable\u003cT, H\u003e::dbg(char* name)`\n\n\n**::ins**: Insert something into the hashtable\n\nIf the element already exists it will be overwritten.\nHandles hash collisions.\n\n`T hashtable\u003cT, H\u003e::ins(T value)`\n\n\n**::del**: Delete something from the hashtable\n\nReturns wether or not the action was successful.\nHandles hash collisions.\n\n`bool hashtable\u003cT, H\u003e::del(T value)`\n\n\n**::fnd**: Search for a value in the hashtable\n\n`T hashtable\u003cT, H\u003e::fnd(T value)`\n\n**::fnd**: Search for a value in the hashtable by predicate\n\n\u003e **Warning**: Expensive action\n\n`T hashtable\u003cT, H\u003e::fnd(F\u0026\u0026 pred)`\n\n\n**::has**: Check if the hashtable contains a value\n\n`bool hashtable\u003cT, H\u003e::has(T value)`\n\n\n**::has**: Check if the hashtable contains a value by predicate lambda\n\n\u003e **Warning**: Expensive action\n\n`bool hashtable\u003cT, H\u003e::has(F\u0026\u0026 pred)`\n\n\n**::each**: Iterate through all elements\nIterate through all elements of the hashtable and call fn for every one of them\n\n\u003e **Warning**: Expensive action\n\n`void hashtable\u003cT, H\u003e::each(F\u0026\u0026 fn)`\n\n\n**::clr**: Clear out all elements of the hashtable\n\n\u003e **Warning**: Expensive action\n\n`void hashtable\u003cT, H\u003e::clr()`\n\n\n**::filter**: Filter hashtable elements\n\nTakes a predicate lambda which decides which elements can stay and which get removed.\n\n\u003e **Warning**: Expensive action\n\n`void hashtable\u003cT, H\u003e::filter(F\u0026\u0026 pred)`\n\n\n**::cat**: Concatenate hashtables\nCombine another hashtable with the current one\n\nThis goes through all elements of the other hashtable and adds the elements to the current one.\n\n\u003e **Warning**: Expensive action\n\n`void hashtable\u003cT, H\u003e::cat(hashtable\u003cT, H\u003e other)`\n\n\n\n### hashmap\n\nA hashmap implementation based on the hashtable implementation inspired by doubly-linked lists, linear probing and freelists.\n\n**hashmapinit**: Create hashmap\n\n`hashmap\u003cK, V, H\u003e hashmapinit(size_t capacity, H hash)`\n\n**hashmapfree**: Free hashmap\n\n`void hashmapfree(hashmap\u003cK, V, H\u003e* hm)`\n\n\n**::resize**: Resize the hashmap\n\nThis can be called manually but will also be called internally whenever needed.\nIt might be useful to call this if you already know that you'll add a specific amount of items soon.\n\n`void hashmap\u003cK, V, H\u003e::resize(size_t new_size)`\n\n\n**::dbg**: Print debug information about the state of the hashmap\n\n`void hashmap\u003cK, V, H\u003e::dbg()`\n\n\n**::dbg**: Print debug information about the state of the hashmap\n\nIncludes a name which will be displayed alongside the debug information to tell debug logs apart.\n\n`void hashmap\u003cK, V, H\u003e::dbg(char* name)`\n\n\n**::ins**: Insert something into the hashmap\n\nIf an element with the same key already exists it will be overwritten.\nHandles hash collisions.\n\n`V hashmap\u003cK, V, H\u003e::ins(K key, V value)`\n\n\n**::del**: Delete something from the hashmap by key\n\nReturns the value of the deleted element.\nHandles hash collisions.\n\n`V hashmap\u003cK, V, H\u003e::del(K key)`\n\n\n**::fnd**: Search for a value in the hashmap (by key)\n\n`V hashmap\u003cK, V, H\u003e::fnd(K key)`\n\n\n**::fnd**: Search for a value in the hashmap by predicate (called with both key and value)\n\n\u003e **Warning**: Expensive action\n\n`template\u003cclass F\u003e V hashmap\u003cK, V, H\u003e::fnd(F\u0026\u0026 pred)`\n\n\n**::has**: Check if the hashmap contains a value (by key)\n\n`bool hashmap\u003cK, V, H\u003e::has(K key)`\n\n\n**::has**: Check if the hashmap contains a value by predicate lambda (called with both key and value)\n\n\u003e **Warning**: Expensive action\n\n`template\u003cclass F\u003e bool hashmap\u003cK, V, H\u003e::has(F\u0026\u0026 pred)`\n\n\n**::each**: Iterate through all elements of the hashmap and call fn for every one of them (with both key and value)\n\n\u003e **Warning**: Expensive action\n\n`template\u003cclass F\u003e void hashmap\u003cK, V, H\u003e::each(F\u0026\u0026 fn)`\n\n\n**::clr**: Clear out all elements of the hashmap\n\n\u003e **Warning**: Expensive action\n\n`void hashmap\u003cK, V, H\u003e::clr()`\n\n\n**::filter**: Filter hashmap elements.\n\nTakes a predicate lambda which decides which elements can stay and which get removed (called with both key and value).\n\n\u003e **Warning**: Expensive action\n\n`template\u003cclass F\u003e void hashmap\u003cK, V, H\u003e::filter(F\u0026\u0026 pred)`\n\n\n**::cat**: Merge another hashmap with the current one\n\nThis goes through all elements of the other hashmap and adds the elements to the current one.\n\n\u003e **Warning**: Expensive action\n\n`void hashmap\u003cK, V, H\u003e::cat(hashmap\u003cK, V, H\u003e other)`\n\n\n### minheap\n\nA minheap implementation.\n\n\n**minheapinit**: Create a new minheap using an initial capacity.\n\n`template\u003cclass T\u003e static minheap\u003cT\u003e minheapinit(size_t capacity)`\n\n\n**minheapfree**: Free minheap\n\n`template\u003cclass T\u003e void minheapfree(minheap\u003cT\u003e heap)`\n\n\n**::resize**: Resize the minheap\n\nThis can be called manually but will also be called internally whenever needed.\nIt might be useful to call this if you already know that you'll add a specific amount of items soon.\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::resize(size_t new_size)`\n\n\n**::dbg**: Print debug information about the state of the minheap\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::dbg()`\n\n\n**::dbg**: Print debug information about the state of the minheap\n\nIncludes a name which will be displayed alongside the debug information to tell debug logs apart.\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::dbg(char* name)`\n\n\n**::insert**: Insert something into the minheap\n\nO(log n)\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::insert(T el)`\n\n\n**::sift_up**: Correct minheap invariant from the bottom up\n\nMostly used internally.\nIt is assumed that the minheap invariant holds true everywhere except at m_data[i]\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::sift_up(size_t i)`\n\n\n**::sift_down**: Correct minheap invariant from the top down\n\nMostly used internally.\nIt is assumed that the minheap invariant holds true everywhere except at L_CHILD(i) and R_CHILD(i).\n\n`template\u003cclass T\u003e void minheap\u003cT\u003e::sift_down(size_t i)`\n\n\n**::min**: Get the minimum element of the minheap\n\nO(1)\n\n`template\u003cclass T\u003e T minheap\u003cT\u003e::min()`\n\n\n**::delete_min**: Delete minimum element of minheap and return it\n\nO(log n)\n\n`template\u003cclass T\u003e T minheap\u003cT\u003e::delete_min()`\n\n\n\n### unionfind\n\nA union-find implementation using union-by-rank and path-compression.\n\n**unionfindinit**: Create a new unionfind data structure with a given size\n\n\u003e **Warning**: The size cannot be changed later on.\n\n\n**unionfindfree**:: Free unionfind\n\n**::_union**: Join two partitions together\n\nCan be called using any element of a partition, doesn't need to be the root element / representative element of the partition.\n\nReturns wether or not the two partitions did get joined together (only 'fails' if they already are the same)\n\n`bool unionfind::_union(size_t a, size_t b)`\n\n\n**::find**: Find the partition (identified by a representative element) of the given element\n\nTime complexity: O(α(n)) amortized with α being the inverse Ackerman function (inverse of A(n, n)).\nThis can effectively be ignored as it's value is below 5 for almost all practical values of n.\n\n`size_t unionfind::find(size_t a)`\n\n\n**::non_destructive_find**: Like find but does not mutate the data structure\n\n\u003e **Warning**: only useful for testing, performance is bad.\n\n`size_t unionfind::non_destructive_find(size_t a)`\n\n\n**::dbg**: Print debug information about the state of the union find structure\n\n`void unionfind::dbg()`\n\n**::dbg**: Print debug information about the state of the union find structure\n\nIncludes a name which will be displayed alongside the debug information to tell debug logs apart.\n\n`void unionfind::dbg(char* name)`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaninawibker%2Falt-stdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaninawibker%2Falt-stdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaninawibker%2Falt-stdlib/lists"}