Coder Social home page Coder Social logo

wpsteak / collections-c Goto Github PK

View Code? Open in Web Editor NEW

This project forked from srdja/collections-c

0.0 1.0 0.0 1.27 MB

A library of generic data structures.

Home Page: http://blog.srdja.me/Collections-C

License: GNU Lesser General Public License v3.0

Makefile 0.76% Shell 3.03% M4 0.14% C 96.07%

collections-c's Introduction

Build Status

Collections-C

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

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
HashTable *table
if (hashtable_new(&table) != CC_OK) {
    // something went wrong
    ...
}

// Add key-value pair
if (hashtable_add(table, "some_key", "some_value") != CC_OK) {
    // something went wrong
    ...
}

// Retrieve a value associated with a key
char *value;
if (hashtable_get(table, "some_key", (void*) &value) == CC_OK)
    printf("%s", value);

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

hashtable_destroy(table);

Array (dynamic array):

// Create a new array
Array *ar;
if (array_new(&ar) != CC_OK) {
    // something went wrong
    ...
}

// Add an element
enum cc_stat status = array_add(ar, "foo");
if (status == CC_OK) {
    ...
} else if (status == CC_ERR_ALLOC) {
    ...
} else {
    ...
}

// Retrieve a value
char *foo;
array_get_at(ar, 0, (void*) &foo);

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

array_destroy(ar);

Installation

####Dependencies

  • gcc
  • autoconf
  • automake
  • libtool
  • m4

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

In the project directory, run the following commands: ./autogen.sh then run ./configure. If autogen complains that it couldn't find a directory named "m4", run: mkdir m4 and then ./autogen.sh.

  • note: Running configure with a prefix like: ./configure --prefix=/some/custom/path will cause make install to install the library to that directory instead of the default one.

At this point we should be able to build the project by running:

make

By default make builds a shared library. To build a static library, run make with "static" flag on: make CFLAGS=-static.

  • note: When building for the 64 bit architecture, "ARCH_64" can be explicitly set like so: make CFLAGS=-DARCH_64. This will increase the maximum container capacity to ~2^64. Otherwise the maximum capacity defaults to ~2^32 elements regardless of the target architecture.

Installing the library:

make install

The tests can be run by:

make check

Compiling and linking a simple program

  • hello.c
#include <stdio.h>
#include <array.h>

int main(int argc, char **argv) {
    Array *ar;
    array_new(&ar);
    array_add(ar, "Hello World!\n");
    
    char *str;
    array_get(ar, 0, (void*) &str);
    printf("%s", str);
    
    return 0;
}

We can now build and statically link the library to our program:

gcc hello.c -I/path/to/library/include/ -static -L/path/to/library/lib/ -lcollectc -o hello

Contributors

All contributions are welcome.

See CONTRIBUTING.md for details.

collections-c's People

Contributors

adamcanady avatar ankurdh avatar f2404 avatar jjungo avatar nekel-seyew avatar pkill37 avatar srdja avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.