Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/nyuichi/ralist

Purely Functional Random-Access List on C++
https://github.com/nyuichi/ralist

Last synced: 20 days ago
JSON representation

Purely Functional Random-Access List on C++

Awesome Lists containing this project

README

        

* Purely Functional Random-Access List

A straight port of Purely Functional Random-Access List by Chris Okasaki to C++.

Every method of RandomAccessList class doesn't check if the passed index is valid or not: you have to check it by hand before calling.
Likewise, every time taking the head or tail of a list you have to make sure that it is not empty.
Since this data structure is purely functional, all operations are done without chaning any part of the existing data.

** HowToUse:
Just include ralist.h.

** APIs:
- RandomAccessList() ::
constructor
- const RandomAccessList *cons(T x) const ::
Returns a newly allocated RandomAccessList. This operation takes O(1) time.
- T lookup(size_t i) const ::
Returns the value at i. Please verify i is in the range of the list before call. This operation takes O(logn) time.
- const RandomAccessList *update(size_t i, T y) const ::
Returns a list whose value at i has been replaced by y. This operation takes O(logn) time both in average and in the worst case.
- bool is_empty() const ::
Complexity: O(1).
- T head() const ::
Complexity: O(1).
- const RandomAccessList *tail() const ::
Complexity: O(1).