Skip to content

Commit

Permalink
add libds
Browse files Browse the repository at this point in the history
  • Loading branch information
Matei94 committed Mar 12, 2015
1 parent 3d70a30 commit 19a07f8
Show file tree
Hide file tree
Showing 23 changed files with 1,977 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libds/.gitignore
@@ -0,0 +1,4 @@
*test
*.o
libds.a
*.swp
18 changes: 18 additions & 0 deletions libds/LICENSE
@@ -0,0 +1,18 @@
Copyright (c) 2011 Zhehao Mao

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions libds/Makefile
@@ -0,0 +1,29 @@
CFLAGS=-O2 -Wall
LDFLAGS=-L. -lds
HEADERS=list.h vector.h hashmap.h strutils.h heap.h tree.h
OBJS=list.o vector.o hashmap.o strutils.o heap.o tree.o
PREFIX=/usr/local
CC=gcc

libds.a: $(OBJS)
ar rcs libds.a $(OBJS)

test: listtest vectest maptest strutiltest heaptest treetest

ds.h: $(HEADERS)
cat $(HEADERS) | sed -e 's/#include "vector.h"//' > ds.h

%test: %test.c libds.a
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@

%.o: %.c %.h
$(CC) $(CFLAGS) -c $<

clean:
rm -f *test *.o *.a

install: ds.h libds.a
mkdir -p $(PREFIX)/lib
cp libds.a $(PREFIX)/lib
mkdir -p $(PREFIX)/include
cp ds.h $(PREFIX)/include
33 changes: 33 additions & 0 deletions libds/README
@@ -0,0 +1,33 @@
libds - Simple, Memory-Safe Data Structures in C
========================================================================

This is a collection of C implementations of common data structures that
I use in many of my C projects. It includes the following procedures and
data structures.

Hashmap
Vector (auto-expanding array)
Linked List
String Buffer (auto-expanding, length-recording string)

Installation Instructions:

Running make with no arguments will generate a shared library named libds.a.
You can then copy that library, as well as all header files, into your
project directory. If you do not wish to use separate header files, you may
generate a single header file called ds.h by running make ds.h.

You can link your applications to the static library like so.

gcc -static main.c -L. -lds -o main

Assuming that main.c is your program and libds.a has been copied into the
same directory.

Documentation on how to use the various functions and datastructures can be
found in the header files.

License:

libds is distributed under the MIT License, the full text of which is
reproduced in LICENSE.

0 comments on commit 19a07f8

Please sign in to comment.