Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/garfield1002/jrsl

A C/C++ implementation of William Pugh's Skip Lists with width
https://github.com/garfield1002/jrsl

c c89 cpp library public-domain single-header-lib skiplist

Last synced: about 1 month ago
JSON representation

A C/C++ implementation of William Pugh's Skip Lists with width

Awesome Lists containing this project

README

        

# C/C++ Skip List Implementation

This is C89 implementation of the data type described in [William Pugh's paper](https:www.epaperpress.com/sortsearch/download/skiplist.pdf) with widths.

> Skip lists are a data structure that can be used in place of balanced trees.
> Skip lists use probabilistic balancing rather than strictly enforced balancing
> and as a result the algorithms for insertion and deletion in skip lists are
> much simpler and significantly faster than equivalent algorithms for
> balanced trees.

Using widths allows for efficient random access.

Although this library will work with C and C++, if you perfer fancy C++ objects you can check out [my first implementation of skip lists](https://github.com/Garfield1002/jhr_skip_list)

## 💡 Why use Skip Lists ?

Skip Lists allow insertion, deletion, random access and search in O(log n) on average (and O(n) in worst case).
Skip lists are a simple data structure that can be used in place of balanced trees for most applications and are much less daunting.

## 📚 Usage

**This library is written in standard C89 for portability.**

The idea behind single-header file libraries is that they're easy to distribute and deploy because all the code is contained in a single file.
The .h file acts as its own header files, i.e. it declares the functions and classes contained in the file but no code is getting compiled.

So in addition, you should select _exactly_ one C/C++ source file that actually instantiates the code, preferably a file you're not editing frequently.
This file should define `JRSL_IMPLEMENTATION` to actually enable the function definitions.

You can check out [example.c](https://github.com/Garfield1002/jrsl/blob/master/example/example.c) for some sample code.

### Skip List Methods

---


Function
Effect



Creation and deletion



jrsl_initialize()
Initializes a skip list



jrsl_destroy()
Cleans up a skip list



Size and capacity



jrsl_max_level()
Calculates the optimal maximum for the amount of levels



Element access



jrsl_data_at()
Returns the data at a particular index



jrsl_key_at()
Returns the key at a particular index



Modification



jrsl_insert()
Inserts an element (a key and some data) in the skip list and returns `NULL`



jrsl_remove()
Removes an element from the skip list, deletes the key and returns it's data



Searching



jrsl_search()
Returns the data of the node with a given key



Visualization



jrsl_display_list()
Prints a visual representation of the skip list

## ⭐ Contribution

All contributions are welcome!

## ⚖ License

This library is in the public domain. You can do anything you want with it. You have no legal obligation to do anything else, although I appreciate attribution.

It is also licensed under the MIT open source license, if you have lawyers who are unhappy with public domain. The source file includes an explicit dual-license for you to choose from.