Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functional data structures in C++

Does anyone know of a C++ data structure library providing functional (a.k.a. immutable, or "persistent" in the FP sense) equivalents of the familiar STL structures?

By "functional" I mean that the objects themselves are immutable, while modifications to those objects return new objects sharing the same internals as the parent object where appropriate.

Ideally, such a library would resemble STL, and would work well with Boost.Phoenix (caveat- I haven't actually used Phoenix, but as far as I can tell it provides many algorithms but no data structures, unless a lazily-computed change to an existing data structure counts - does it?)

like image 686
drg Avatar asked May 03 '10 10:05

drg


People also ask

What is data structure function?

Data structures bring together the data elements in a logical way and facilitate the effective use, persistence and sharing of data. They provide a formal model that describes the way the data elements are organized. Data structures are the building blocks for more sophisticated applications.

What are the 2 main types of data structures?

There are two fundamental kinds of data structures: array of contiguous memory locations and linked structures.


2 Answers

I would look and see whether FC++ developed by Yannis Smaragdakis includes any data structures. Certainly this project more than any other is about supporting a functional style in C++.

like image 139
Norman Ramsey Avatar answered Oct 02 '22 01:10

Norman Ramsey


This is more of a heads up than a detailed answer, but Bartosz Milewski appears to have done a lot of work on this. See, for example:

http://bartoszmilewski.com/2013/11/13/functional-data-structures-in-c-lists/

Looks like he's implemented a lot of algorithms from Okasiki's book Purely Functional Data Structures here:

https://github.com/BartoszMilewski/Okasaki

N.B. I haven't tried these yet, but they're the first C++ persistent data structures I've seen outside of FC++.

Hopefully, I'll get to trying them soon.

like image 28
TerrestrialIntelligence Avatar answered Oct 02 '22 00:10

TerrestrialIntelligence