A lightweight, modular standard library extension, string library, and interfaces to various libraries (unix, threads, etc.) BSD license.
Find a file
2014-11-30 14:13:52 -05:00
advanced breaking change: renamed CCIO to advanced.CCMonadIO; new CCIO module, much simpler 2014-11-23 13:05:30 +01:00
benchs move misc/Cache to core/CCCache 2014-11-23 13:48:52 +01:00
cgi remove generated files 2014-05-21 00:20:12 +02:00
core CCOpt: add get_lazy convenience function 2014-11-30 14:13:52 -05:00
examples moved Sexp into core/CCSexp 2014-09-30 16:14:16 +02:00
lwt updated readme and doc 2014-11-23 15:48:18 +01:00
misc prepare for 0.6 2014-11-23 14:14:46 +01:00
pervasives merge back from stable 2014-11-12 00:42:28 +01:00
sequence Merge commit '36423c01d2ab8881c9f8ac6d43fb7c945b0add59' from sequence 2014-11-04 22:19:27 +01:00
string Levenshtein.Index.remove changed signature (useless param removed) 2014-11-08 01:24:39 +01:00
tests quick test for Lwt_actors 2014-11-20 01:11:20 +01:00
threads renamed threads/future to threads/CCFuture 2014-08-05 00:23:04 +02:00
.gitignore qtest 2014-05-12 15:30:13 +02:00
.header Cause: debugging experiment, tracking why values exist and actions were performed 2014-04-23 17:59:43 +02:00
.merlin use CCBench in benchs/benchs.ml to hierarchize benchmarks 2014-11-13 15:41:30 +01:00
.ocamlinit Squashed 'sequence/' changes from 2691bee..efeb0fc 2014-11-04 22:19:26 +01:00
_oasis introduce CCFloat, add float functions to CCRandom 2014-11-28 13:00:42 -05:00
_tags stronger inlining for CCVector (so that e.g. push is inline) 2014-11-10 00:49:45 +01:00
AUTHORS.md add missing @since annotations, updated authors 2014-11-30 18:30:11 +01:00
CHANGELOG.md updated readme and doc 2014-11-23 15:48:18 +01:00
configure thanks to @whitequark, could use cppo for preprocessing files 2014-11-04 15:22:09 +01:00
HOWTO.md update authors.md 2014-11-23 15:36:53 +01:00
LICENSE gitignore and update of readme; added LICENSE file (BSD) 2013-02-27 16:12:14 +01:00
Makefile updated readme and doc 2014-11-23 15:48:18 +01:00
META Squashed 'sequence/' changes from 2691bee..efeb0fc 2014-11-04 22:19:26 +01:00
myocamlbuild.ml Squashed 'sequence/' changes from 2691bee..efeb0fc 2014-11-04 22:19:26 +01:00
opam opam file 2014-11-20 01:05:20 +01:00
README.md update readme 2014-11-28 13:04:04 -05:00
setup.ml Squashed 'sequence/' changes from 2691bee..efeb0fc 2014-11-04 22:19:26 +01:00

ocaml-containers

  1. A usable, reasonably well-designed library that extends OCaml's standard library (in core/, packaged under containers in ocamlfind. Modules are totally independent and are prefixed with CC (for "containers-core" or "companion-cube" because I'm megalomaniac). This part should be usable and should work. For instance, CCList contains functions and lists including safe versions of map and append.
  2. A satellite library, containers.string (in directory string) with a few packed modules that deal with strings (Levenshtein distance, KMP search algorithm, and a few naive utils). Again, modules are independent and sometimes parametric on the string and char types (so they should be able to deal with your favorite unicode library).
  3. A drop-in replacement to the standard library, containers.pervasives, that defined a CCPervasives module intented to be opened to extend some modules of the stdlib.
  4. A sub-library with complicated abstractions, containers.advanced (with a LINQ-like query module, batch operations using GADTs, and others)
  5. A library using Lwt, containers.lwt. Currently only contains experimental, unstable stuff.
  6. Random stuff, with NO GUARANTEE of even being barely usable or tested, in other dirs (mostly misc but also lwt and threads). It's where I tend to write code when I want to test some idea, so half the modules (at least) are unfinished or don't really work.

Some of the modules have been moved to their own repository (e.g. sequence, gen, qcheck) and are on opam for great fun and profit.

Build Status

Change Log

See this file.

Finding help

  • the github wiki
  • the IRC channel (##ocaml-containers on Freenode)

Use

You can either build and install the library (see Build), or just copy files to your own project. The last solution has the benefits that you don't have additional dependencies nor build complications (and it may enable more inlining). Since modules have a friendly license and are mostly independent, both options are easy.

If you have comments, requests, or bugfixes, please share them! :-)

License

This code is free, under the BSD license.

Contents

The design is mostly centered around polymorphism rather than functors. Such structures comprise (some modules in misc/, some other in core/):

Core Structures

the core library, containers, now depends on cppo and base-bytes (provided by ocamlfind).

Documentation here.

  • CCHeap, a purely functional heap structure.
  • CCFQueue, a purely functional double-ended queue structure
  • CCBV, mutable bitvectors
  • CCPersistentHashtbl, a semi-persistent hashtable (similar to persistent arrays)
  • CCVector, a growable array (pure OCaml, no C) with mutability annotations
  • CCGen and CCSequence, generic iterators structures (with structural types so they can be defined in several places). Now also in their own repository and opam packages (gen and sequence).
  • CCKList, a persistent iterator structure (akin to a lazy list)
  • CCList, functions on lists, including tail-recursive implementations of map and append and many other things
  • CCArray, utilities on arrays and slices
  • CCMultimap and CCMultiset, functors defining persistent structures
  • CCHashtbl, CCMap extensions of the standard modules Hashtbl and Map
  • CCFlatHashtbl, a flat (open-addressing) hashtable functorial implementation
  • CCKTree, an abstract lazy tree structure (similar to what CCKlist is to lists)
  • CCTrie, a prefix tree
  • small modules (basic types, utilities):
    • CCInt
    • CCString (basic string operations)
    • CCPair (cartesian products)
    • CCOpt (options, very useful)
    • CCFun (function combinators)
    • CCBool
    • CCFloat
    • CCOrd (combinators for total orderings)
    • CCRandom (combinators for random generators)
    • CCPrint (printing combinators)
    • CCHash (hashing combinators)
    • CCError (monadic error handling, very useful)
  • CCSexp, a small S-expression library
  • CCIO, basic utilities for IO
  • CCCache, memoization caches, LRU, etc.

String

See doc.

In the module Containers_string:

  • Levenshtein: edition distance between two strings
  • KMP: Knuth-Morris-Pratt substring algorithm

Advanced

See doc.

In the module Containers_advanced:

  • CCLinq, high-level query language over collections
  • CCCat, a few categorical structures
  • CCBatch, to combine operations on collections into one traversal

Misc

See doc. This list is not necessarily up-to-date.

  • PHashtbl, a polymorphic hashtable (with open addressing)
  • SplayTree, a polymorphic splay heap implementation (not quite finished)
  • SplayMap, a polymorphic functional map based on splay trees
  • Heap, an imperative heap based on SplayTree
  • Graph, a polymorphic imperative directed graph (on top of PHashtbl)
  • Hashset, a polymorphic imperative set on top of PHashtbl
  • LazyGraph, a lazy graph structure on arbitrary (hashable+eq) types, with basic graph functions that work even on infinite graphs, and printing to DOT.
  • Heap, a purely functional polymorphic heap
  • Bij, a GADT-based bijection language used to serialize/deserialize your data structures
  • RAL, a random-access list structure, with O(1) cons/hd/tl and O(ln(n)) access to elements by their index.
  • SmallSet, a sorted list implementation behaving like a set.
  • AbsSet, an abstract Set data structure, a bit like LazyGraph.
  • Univ, a universal type encoding with affectation
  • FlatHashtbl, a (deprecated) open addressing hashtable with a functorial interface (replaced by PHashtbl)
  • UnionFind, a functorial imperative Union-Find structure.

Others

  • Future, a set of tools for preemptive threading, including a thread pool, monadic futures, and MVars (concurrent boxes)

Some serialisation formats are also implemented, with a streaming, non-blocking interface that allows the user to feed the input in chunk by chunk (useful in combination with Lwt/Async). Currently, the modules are:

There is a QuickCheck-like library called QCheck (now in its own repo).

Build

You will need OCaml >= 4.01.0.

Via opam

The prefered way to install is through opam.

$ opam install containers

From Sources

On the branch master you will need oasis to build the library. On the branch stable it is not necessary.

$ make

To build and run tests (requires oUnit and qtest):

$ opam install oUnit
$ make tests
$ ./tests.native

and

$ opam install qtest
$ make qtest

To build the small benchmarking suite (requires benchmark):

$ opam install benchmark
$ make bench
$ ./benchs.native

Contributing

PRs on github are welcome (patches by email too, if you prefer so).

A few guidelines:

  • no dependencies between basic modules (even just for signatures)
  • add @since tags for new functions
  • add tests if possible (using qtest)