Skip to content

Repository files navigation

Reestruct Library

A comprehensive C library providing various data structure implementations with generic type support.


🚀 Features

  • Generic data structures using void* (type-agnostic)
  • Memory leak prevention and safety checks
  • Consistent API design across all structures
  • Support for both static and dynamic library builds
  • Ordered & unordered associative containers (map/set/umap/uset)
  • Ready-to-ship release layout (release/include + release/lib)

📚 Data Structures

StructureDescriptionHeader
Singly Linked ListLinear collection with forward traversallinkedlist.h
Doubly Linked ListBi-directional linear collectionlinkedlist.h
StackLIFO data structurestack.h
QueueFIFO data structurequeue.h
DequeDouble-ended queuedeque.h
Binary TreeTree with max 2 children per nodebinarytree.h
HeapBinary heap (min-heap via comparator)heap.h
MapOrdered map (BST + comparator)map.h
SetOrdered set (BST + comparator)set.h
Unordered MapHash mapumap.h
Unordered SetHash setuset.h
GraphAdjacency-list graphgraph.h

✅ Implemented Data Structures

  • Singly Linked List
  • Doubly Linked List
  • Stack
  • Queue
  • Deque
  • Binary Tree
  • Heap
  • Map / Set
  • Unordered Map / Unordered Set
  • Graph

🧠 Usage

⚡ Quick Start

make release
gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main

Place the built library (release/lib) alongside your binary or update PATH/LD_LIBRARY_PATH as needed.

🛠 One-command build (auto-detect OS)

bash scripts/build.sh # defaults to release
bash scripts/build.sh static # or shared / all / clean / test / docs

On Windows, run the script from Git Bash/MSYS2/WSL so make is available. The script sets OS for the Makefile automatically.

✅ Run unit tests

make test# or
bash scripts/build.sh test

📖 Generate Doxygen docs

Requires doxygen installed:

make docs
# or
bash scripts/build.sh docs

Output: docs/html/index.html.

📥 Include Example

You can include all structures:

#include"reestruct.h"

Atau untuk lebih efisien (khusus kebutuhan):

#include"linkedlist.h"// Only linked list#include"stack.h"// Only stack#include"queue.h"// Only queue#include"deque.h"// Only deque#include"binarytree.h"// Only binary tree

💡 Example Program

#include"stack.h"#include<stdio.h>voidprintInt(void*data) {
printf("%d ", *(int*)data);
}
intmain() {
Stack*stack=createStack();
intnums[] = {1, 2, 3, 4, 5};
for(inti=0; i<5; i++) {
push(stack, &nums[i]);
}
printStack(stack, printInt);
freeStack(stack);
return0;
}

🌳 Map / Set Example (ordered, comparator-based)

#include"map.h"#include<stdio.h>intintCompare(constvoid*a, constvoid*b) {
intda=*(constint*)a;
intdb=*(constint*)b;
return (da>db) - (da<db);
}
voidprintPair(void*key, void*value) {
printf("%d => %s\n", *(int*)key, (char*)value);
}
intmain() {
Map*map=createMap(intCompare);
intkey1=10, key2=5;
mapPut(map, &key1, "ten");
mapPut(map, &key2, "five");
mapTraverseInOrder(map, printPair);
freeMap(map);
}

🧭 Unordered Map / Set (hash-based)

#include"umap.h"#include<string.h>#include<stdio.h>size_tstrHash(constvoid*key) {
// djb2-ishsize_th=5381;
constunsigned char*p= (constunsigned char*)key;
while (*p) h= ((h << 5) +h) +*p++;
returnh;
}
boolstrEq(constvoid*a, constvoid*b) {
returnstrcmp((constchar*)a, (constchar*)b) ==0;
}
intmain() {
UMap*map=createUMap(strHash, strEq);
umapPut(map, "hello", "world");
printf("%s\n", (char*)umapGet(map, "hello"));
freeUMap(map);
}

🧩 Linking

Static Library (.a)

gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main

Shared Library (.dll / .so)

Windows:

gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main.exe
# Make sure reestruct.dll is in the same folder or in PATH

Linux:

gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main
# Ensure libreestruct.so is in LD_LIBRARY_PATH

📦 Installation

  1. Download the latest release from the GitHub Releases Page
  2. Extract the files to your project directory
  3. Include the appropriate headers in your code

⚙️ Building

Gunakan Makefile yang disediakan:

# Build both static and shared libraries
make all
# Build only static library (.a)
make static
# Build only shared library (.dll/.so)
make shared
# Generate release folder
make release
# Clean build files
make clean

📚 Release Structure

release/
├── include/
│ ├── reestruct.h
│ ├── stack.h
│ ├── queue.h
│ ├── linkedlist.h
│ └── ...
└── lib/
├── libreestruct.a
└── reestruct.dll / libreestruct.so

🤝 Contributing

Contributions are welcome! Please feel free to submit pull requests.


📄 License

This project is licensed under the MIT License.


👤 Author

riefproject – Author & Maintainer

About

C data structure library featuring a type-agnostic design via void*. Offers memory-safe implementations of Singly/Doubly Linked Lists, Stacks, Queues, and Deques with a consistent API. Supports both static (.a) and dynamic (.dll/.so) builds for easy integration into any C project.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages