All Projects → srdja → Collections C

srdja / Collections C

Licence: lgpl-3.0
A library of generic data structures.

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to Collections C

Sc
Common libraries and data structures for C.
Stars: ✭ 161 (-92.99%)
Mutual labels:  algorithms, data-structures, collections, library
Competitiveprogramming
A collection of algorithms, data structures and other useful information for competitive programming.
Stars: ✭ 475 (-79.32%)
Mutual labels:  algorithms, data-structures, library
Lib9wada
Wonderful library with lots of useful functions, algorithms and data structures in C, link it with -l9wada
Stars: ✭ 35 (-98.48%)
Mutual labels:  algorithms, data-structures, library
Towel
Throw in the towel.
Stars: ✭ 333 (-85.5%)
Mutual labels:  algorithms, data-structures, library
Best Of Python
🏆 A ranked list of awesome Python open-source libraries and tools. Updated weekly.
Stars: ✭ 1,869 (-18.63%)
Mutual labels:  data-structures, collections, library
Rust Algorithm Club
Learn algorithms and data structures with Rust
Stars: ✭ 184 (-91.99%)
Mutual labels:  algorithms, data-structures
Embb
Embedded Multicore Building Blocks (EMB²): Library for parallel programming of embedded systems. Star us on GitHub? +1
Stars: ✭ 153 (-93.34%)
Mutual labels:  algorithms, data-structures
Algorithms Leetcode Javascript
Algorithms resolution in Javascript. Leetcode - Geeksforgeeks - Careercup
Stars: ✭ 157 (-93.16%)
Mutual labels:  algorithms, data-structures
Data Structures Algorithms
Your personal library of every algorithm and data structure code that you will ever encounter
Stars: ✭ 157 (-93.16%)
Mutual labels:  algorithms, data-structures
C Plus Plus
Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
Stars: ✭ 17,151 (+646.67%)
Mutual labels:  algorithms, data-structures
Programmers Community
This repository contains various solution of a problem in Ruby, C, C++, Python and Java.
Stars: ✭ 189 (-91.77%)
Mutual labels:  algorithms, data-structures
Opends
Template Library of Data Structures in C++17
Stars: ✭ 151 (-93.43%)
Mutual labels:  data-structures, library
Leetcode In Swift
My solutions to LeetCode problems written in Swift
Stars: ✭ 150 (-93.47%)
Mutual labels:  algorithms, data-structures
Pygm
🐍 Python library implementing sorted containers with state-of-the-art query performance and compressed memory usage
Stars: ✭ 156 (-93.21%)
Mutual labels:  algorithms, data-structures
Graphlib
Simple but powerful graph library for Rust
Stars: ✭ 148 (-93.56%)
Mutual labels:  data-structures, library
Data Structures And Algorithms
Data Structures and Algorithms implemented In Python, C, C++, Java or any other languages. Aimed to help strengthen the concepts of DS&A. Give a Star 🌟 if it helps you.
Stars: ✭ 146 (-93.64%)
Mutual labels:  algorithms, data-structures
Data Structures And Algorithms In Cpp
This repository is in development phase and will soon provide you with c++ code of various data structures and algorithms
Stars: ✭ 176 (-92.34%)
Mutual labels:  algorithms, data-structures
Algorithms Data Structures In Typescript
Stars: ✭ 175 (-92.38%)
Mutual labels:  algorithms, data-structures
Data Structures And Algorithms Hacktoberfest18
List of data structures and algorithms. Feel free to contribute under Hacktoberfest '18!
Stars: ✭ 187 (-91.86%)
Mutual labels:  algorithms, data-structures
Dailycodebase
2 month data structures and algorithmic scripting challenge starting from 20th December 2018 - Coding is Fun! 💯💯 Do it everyday!! Also, Do give us a ⭐ if you liked the repository
Stars: ✭ 186 (-91.9%)
Mutual labels:  algorithms, data-structures

Collections-C

A library of generic data structures including a list, array, hashtable, deque etc..

Build Status License: LGPL v3

Examples

Check the documentation page for mode detailed examples. (This is still in progress). The source of the documentation can be found here.

HashTable

// Crate a new table
CC_HashTable *table;
if (cc_hashtable_new(&table) != CC_OK) {
    // something went wrong
    ...
}
// Add key-value pair
if (cc_hashtable_add(table, "some_key", "some_value") != CC_OK) {
    // something went wrong
    ...
}
// Retrieve a value associated with a key
char *value;
if (cc_hashtable_get(table, "some_key", (void*) &value) == CC_OK)
    printf("%s", value);

// Remove a key
cc_hashtable_remove(table, "foo", NULL);
cc_hashtable_destroy(table);

Array (dynamic array)

// Create a new array
CC_Array *ar;
if (cc_array_new(&ar) != CC_OK) {
    // something went wrong
    ...
}
// Add an element
enum cc_stat status = cc_array_add(ar, "foo");
if (status == CC_OK) {
    ...
} else if (status == CC_ERR_ALLOC) {
    ...
} else {
    ...
}
// Retrieve a value
char *foo;
cc_array_get_at(ar, 0, (void*) &foo);

// Remove a value
char *removed;
cc_array_remove_at(ar, 0, (void*) &removed);

cc_array_destroy(ar);

Building and Installation

Dependencies

  • C compiler (gcc, clang, etc...)
  • cmake (>= 3.5)
  • [testing only] cpputest (>=3.8)
  • pkg-config

These packages can usually be installed through your distributions package manager.

Building on windows requires MinGW which provides all the tools needed to build the project.

Building the project

To build the project, we first need to create a separate build directory:

mkdir build

Now that we've created our build directory (assuming it's created in the projct root), we can cd into it and run cmake and pass the parent directory path to it, which is where the CMakeLists.txt file is located:

cd build
cmake ..

Once cmake is done generating makefiles, we can build the library by running make inside our build directory:

make

This will build both the static and the dynamic library.

Running tests

make test

Running individual tests

make build
build/test/array_test -c -v

Installing

To install the library run:

sudo make install

By default the libraries and headers will be installed in /usr/local/lib/ and /usr/local/include directories.

You have to make the system's runtime aware of the location of the new library to be able to run dynamically linked applications. This might be as simple as running the following command if your /etc/ld.so.conf contains the install directory.

Note: macOS doesn't support ldconfig.

sudo ldconfig

Using Collections-C in your programs

A simple program

If we already built and installed the library, we can write a simple hello world program and save it to a file named hello.c:

#include <stdio.h>
#include <collectc/cc_array.h>

int main(int argc, char **argv) {
    // Create a new array
    CC_Array *ar;
    cc_array_new(&ar);

    // Add a string to the array
    cc_array_add(ar, "Hello World!\n");

    // Retreive the string and print it
    char *str;
    cc_array_get_at(ar, 0, (void*) &str);
    printf("%s", str);

    return 0;
}

Now we need to compile and link our program. Since make builds both the static and the dynamic library we can choose which one we wish to link into our program.

Linking statically

If we wish to statically link the library to our program we can pass the -static flag to the compiler

Note: On macOS, the -static flag is not very friendly (it requires that all the libraries are statically linked). So we can replace -static -lcollectc with the full path to the static library. Which is /usr/local/lib/libcollectc.a by default.

gcc hello.c -static -lcollectc -o hello

or similarly when compiling with clang:

clang hello.c -static -lcollectc -o hello

This will link the library by copying it into the executable. We can use this option if we don't wish to have Collections-C as a runtime dependency, however this comes at the expense of generating a larger executable.

Linking dynamically

We can also choose to link with the library dynamically at runtime. This is the default behaviour if ommit the -static compiler flag:

gcc hello.c -lcollectc -o hello

or with clang:

clang hello.c -lcollectc -o hello

Linking dynamically produces a smaller executable, but requires libcollectc.so to be present on every system on which the program is going to be executed.

Linking problems

Sometimes the compiler may have trouble finding the library or the headers. This is usually because it's looking for them in the wrong directory, which may happen if the library or the headers or both are installed in a non-standard directory or not installed at all.

If this is the case, we can explicitly tell the compiler where to look for them by passing the -I[path to headers] and -L[path to libraries] options:

gcc hello.c `pkg-config --cflags --libs collectionc` -o hello

Running the program

If everything went well with the compilation we can run the executable:

./hello

and it should print Hello, World! to the console.

Contributing

Contributions are welcome.

If you have a feature request, or have found a bug, feel free to open a new issue. If you wish to contribute code, see CONTRIBUTING.md for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].