Skip to content

Commit

Permalink
Updated README with more detailed descriptions of items
Browse files Browse the repository at this point in the history
  • Loading branch information
jeraymond committed Jul 29, 2012
1 parent 7cdc173 commit 09f1d07
Showing 1 changed file with 88 additions and 11 deletions.
99 changes: 88 additions & 11 deletions README.md
@@ -1,6 +1,6 @@
# NP Library

A utility c library demonstrating various data structures and algorithms.
A utility C library of various data structures and algorithms.

## Building

Expand All @@ -18,40 +18,117 @@ Builds `src/libnplib.so` then builds and runs a C-Unit based test program in

## Data Structures

### np_linkedlist
### Singly Linked List

np_linkedlist is a singly linked list. The source is located:
The singly [linked list][1] implementation `np_linkedlist` is found at:

src/np_linkedlist.h
src/np_linkedlist.c

[1]: http://en.wikipedia.org/wiki/Linked_list

#### Operations

* __push__ - add an item to the front of the list
* __pop__ - remove the first item in the list
* __reverse__ - reverse order of items in the list
* __length__ - determine the length of the list
* __add__ - add an item at a particular location in the list
* __remove__ - remove an item at a particular location in the list
* __get__ - get an item at a particular location in the list
* __iterator__ - an iterator to iterate over items in the list

See `test/np_linkedlist_test.c` for sample usage.

### np_arraylist
#### Performance

Push and pop operate at the head of the list in constant O(1) time. Add,
remove, and get operate in _search time_ + O(1) time. Searching for an item
by index is a O(i) operation where i is target index. Length and reverse
operate in O(n) linear time. The entire list is traversed to determine its
length or to reverse the list.

The extra space required by the list is linear O(n) relative to the size of
the list.

### Array List

np_arraylist is a dynamic array. The source is located:
The array list (or [dynamic array][2]) implementation `np_arraylist` is found
at:

src/np_arraylist.h
src/np_arraylist.c

[2]:http://en.wikipedia.org/wiki/Dynamic_array

#### Operations

* __push__ - add an item to the front of the list
* __pop__ - remove the first item in the list
* __reverse__ - reverses the order of items in the list
* __length__ - determine the length of the list
* __add__ - add an item at a particular location in the list
* __remove__ - remove an item at a particular location from the list
* __get__ - get an item at a particular location in the list
* __iterator__ - an iterator to iterate over items in the list

See `test/np_arraylist_test.c` for sample usage.

### np_hashmap
#### Performance

Push and pop operate at the head of the list in linear O(n) time. Inserting
or removing list items requires moving all items after the target item in
the list. Add and remove operate generally at linear O(n) time. Adding or
removing at the end of the list is constant O(n) time (amoritized). Get and
length operate in constant O(1) time. Reverse operates in linear O(n) time.

The extra space required by the list is linear O(n) relative to the size
of the list.

### Hash Map

np_hashmap implements a hash based map (hashtable). Hash collisions are
resolved with chaining. The source is located:
The hash map (or [hash table][3]) implementation `np_hashmap` is found at:

src/np_hashmap.h
src/np_hashmap.c

[3]:http://en.wikipedia.org/wiki/Hash_table

#### Operations

* __put__ - associates the given value with the specified key
* __get__ - gets the item associated with the given key
* __remove__ - removes the given key and its assocated value

See `test/np_hashmap_test.c` for sample usage.

### np_treemap
#### Performance

Insert and get operate on average in O(1 + n/k) time and linear O(n) time
in the worst case. Put is constant O(1) in time.

The extra space required by the map is linear O(n) relative to the number
of items in the map.

### Tree Map

np_treemap is a red-black tree based sorted map. The map provides ordering
on the keys based upon a given comparator function. The source is located:
The tree map implementation `np_treemap` is found at:

src/np_treemap.h
src/np_treemap.c

#### Operations

* __put__ - associates the given value with the specified key
* __get__ - gets the item associated with the given key
* __remove__ - removes the given key and its assocated value
* __iterator__ - iterate over map keys in key order

See `test/np_treemap_test.c` for sample usage.

#### Performance

Put, get, and remove operate in logarithmic O(log n) time.

The extra space required by the map is linear O(n) relative to the number
of items in the map.

0 comments on commit 09f1d07

Please sign in to comment.