The documentation has been changed to mdbook
Check it out: https://rust-lang.github.io/mdBook/index.html
This commit is contained in:
1 parent
4e96d3aba0
commit
062c03091c
107 files changed
+9283
-5280
No files matched your search
@@ -0,0 +1,21 @@
|
||||
# How to install
|
||||
|
||||
To start using the library you need first to download the source code. You can either fork the repository or download a zip file containing everything. Either way, after you unzip everything you will end up with the root folder (probably something called `C-Macro-Collections`) and inside it is the `src` folder.
|
||||
|
||||
With the `src` folder you can start including the library headers to your project with `-I path/to/library/src`.
|
||||
|
||||
The library has no external dependencies other than the C standard library.
|
||||
|
||||
```c
|
||||
// Include header files like this
|
||||
#include <cmc/list.h>
|
||||
#include <dev/deque.h>
|
||||
#include <utl/assert.h>
|
||||
```
|
||||
|
||||
```c
|
||||
// Not like this
|
||||
#include <list.h>
|
||||
#include <deque.h> // dev or cmc?
|
||||
#include <assert.h> // this will import from the standard library
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
# How to Use the Library
|
||||
|
||||
The C Macro Collections Library comes with very powerful data structures and they are only one macro away from you.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@@ -0,0 +1,17 @@
|
||||
# Introduction
|
||||
|
||||
<p align="center">
|
||||
<img src="img/logo.png" alt="C Macro Collections Logo" width="300"/>
|
||||
</p>
|
||||
|
||||
<p align="center">Header only, macro generated, generic and type-safe Collections in C.</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/LeoVen/C-Macro-Collections/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License"/></a>
|
||||
<a href="https://travis-ci.org/LeoVen/C-Macro-Collections"><img src="https://travis-ci.org/LeoVen/C-Macro-Collections.svg?branch=master" alt="travis-ci"/></a>
|
||||
<a href="https://codecov.io/gh/LeoVen/C-Macro-Collections"><img src="https://codecov.io/gh/LeoVen/C-Macro-Collections/branch/master/graph/badge.svg" alt="codecov"/></a>
|
||||
</p>
|
||||
|
||||
The C Macro Collections Library is a compilation of macros that can be used to generate common data structures for any desired type. These data structures are [type safe](https://en.wikipedia.org/wiki/Type_safety) and are powered with many features (see Features section).
|
||||
|
||||
The documentation is currently being written in hopes that in the future it can be used to help you get to know better this amazing C library.
|
||||
@@ -0,0 +1,29 @@
|
||||
# Library Structure
|
||||
|
||||
The `src` folder is subdivided in 5 other folders and one file:
|
||||
|
||||
* __cmc__ - The main C Macro Collections Library
|
||||
* __dev__ - The main C Macro Collections Library for development
|
||||
* __sac__ - Statically Allocated Collections
|
||||
* __utl__ - Utility like ForEach macros, logging, etc
|
||||
* __macro\_collections.h__ - Master header containing all collections and utilities
|
||||
|
||||
## cmc
|
||||
|
||||
This is where the C Macro Collections are hosted.
|
||||
|
||||
## dev
|
||||
|
||||
In this folder is an exact copy of the `cmc` Collections with the added logging utility (`./utl/log.h`). These are useful to debug your code because everything that is happening inside the data structure can be seen.
|
||||
|
||||
## sac
|
||||
|
||||
This is where the Statically Allocated Collections are hosted. These collections are just like the `cmc` Collections but they have a constant size, a C array, instead of a dynamically allocated array (yes, even for Linked List).
|
||||
|
||||
## utl
|
||||
|
||||
Utility. Here you will find things like assert macros, foreach macros, logging utility, unit test and timer.
|
||||
|
||||
## macro_collections.h
|
||||
|
||||
This is the master header. Include this big boy and all functionalities of the library will be in your hands.
|
||||
@@ -0,0 +1,57 @@
|
||||
# Understanding the Library
|
||||
|
||||
Every macro within the library is prefixed by `CMC` or `cmc`. If you have [intellisense](https://code.visualstudio.com/docs/editor/intellisense) you can easily check all the features of the library once you include the necessary headers.
|
||||
|
||||
When you generate code for a certain collection you will need to pass four very important parameters: `SNAME`, `PFX`, `K` and `V`.
|
||||
|
||||
## SNAME
|
||||
|
||||
`SNAME` is short for struct name. This parameter will define your collection so that its type name becomes:
|
||||
|
||||
```c
|
||||
struct SNAME;
|
||||
```
|
||||
|
||||
No `typedef`s are used within the code that is generated in order to not pollute the global namespace. If you wish to `typedef` feel free to give your own naming conventions.
|
||||
__Every other `struct` that is generated as part of the implementation will be prefixed by `SNAME`__. So iterators and nodes will become:
|
||||
|
||||
```c
|
||||
struct SNAME##_iter;
|
||||
struct SNAME##_node;
|
||||
```
|
||||
|
||||
Note that the `##` is a [Token Pasting Operator](https://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation).
|
||||
|
||||
## PFX
|
||||
|
||||
`PFX` is a short for prefix. __Every function generated will be within this namespace__. When using [Intellisense](https://code.visualstudio.com/docs/editor/intellisense), write whichever prefix you gave to your functions and everything will be in there.
|
||||
|
||||
Functions that are part of the implementation and shouldn't be called directly are prefixed by `PFX` and then by `_impl_`. Every iterator function will be prefixed by `PFX` and then by `_iter_`. For example:
|
||||
|
||||
```c
|
||||
// A function that you shouldn't use directly
|
||||
size_t PFX##_impl_quick_sort(struct SNAME *list);
|
||||
```
|
||||
|
||||
```c
|
||||
// A function that is associated with the iterator
|
||||
struct SNAME##_iter *PFX##_iter_new(struct SNAME *target);
|
||||
```
|
||||
|
||||
## K
|
||||
|
||||
`K`, short for Key, is the data type that is only used by associative collections to map a key to a value.
|
||||
|
||||
## V
|
||||
|
||||
`V`, short for Value, is the primary data type for most collections.
|
||||
|
||||
## Summarizing
|
||||
|
||||
With `SNAME` and `PFX` a common function definition looks like:
|
||||
|
||||
`size_t PFX##_count(struct SNAME *list);`
|
||||
|
||||
So if input `SNAME` as `i32list` and `PFX` as `i32l` you will have the following function definition:
|
||||
|
||||
`size_t i32l_count(struct i32list *list);`
|
||||
@@ -0,0 +1,18 @@
|
||||
# Why this library
|
||||
|
||||
C is a low level language and lacks all the data structures that we commonly use. Many high level languages already come with these collections so that we don't have to implement everything ourselves. A lot of third party libraries that implement these missing data structures for the C language usually make use of a void pointers and a lot of macros. __This is why the C Macro Collections Library was created.__ All you need to do is to write down one macro and which data type you wish to work with. The library currently provides many data structures, such as:
|
||||
|
||||
* __Linear Collections__ : List, LinkedList, Deque, Stack, Queue, SortedList
|
||||
* __Sets__ : HashSet, TreeSet, MultiSet
|
||||
* __Maps__ : HashMap, TreeMap, MultiMap, BidiMap
|
||||
* __Heaps__ : Heap, IntervalHeap
|
||||
|
||||
All with the following features:
|
||||
|
||||
* __Type-safe__ - No `void *` pointers are used. A collection of type `int` will only accept integers;
|
||||
* __Customization__ - Custom struct name and function namespace;
|
||||
* __Bidirectional Iterators__ - Full support for iterators;
|
||||
* __Nesting__ - Collections can be nested (List of Lists, HashSet of Stacks, etc);
|
||||
* __One macro to rule them all__ - Only one macro to generate everything and that's it.
|
||||
|
||||
and many other powerful features (see [Features](../Features/features.html)).
|
||||
Reference in new issue
Block a user