Coder Social home page Coder Social logo

allengaller / collections-c Goto Github PK

View Code? Open in Web Editor NEW

This project forked from srdja/collections-c

0.0 3.0 0.0 943 KB

A library of generic data structures.

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

License: GNU Lesser General Public License v3.0

Makefile 0.84% Shell 3.82% C 95.35%

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 for details. And the wiki for more detailed examples (currently in progress).

HashTable:

HashTable *table = hashtable_new();

hashtable_add(table, "some_key", "some_value");
hashtable_add(table, "foo", "bar");

char *value   = hashtable_get(table, "foo");    // returns "bar"
char *removed = hashtable_remove(table, "foo"); // removes the key and returns the value

hashtable_destroy(table);

Array (dynamic array):

Array *vec = array_new();

array_add(vec, "foo");
array_add(vec, "bar");
array_add(vec, "baz");

char *foo = array_get(vec, 0);
char *baz = array_get(vec, 2);

char *removed = array_remove_at(vec, 1);

array_destroy(vec);

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();
    array_add(ar, "Hello World!\n");
    
    printf("%s", (char*) array_get(ar, 0));
    
    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

Contributions are very much welcome.

collections-c's People

Contributors

adamcanady avatar srdja avatar

Watchers

 avatar  avatar  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.