Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion data/tutorials/language/3ds_02_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ category: "Data Structures"

In the most general sense, the [`Map`](/manual/api/Map.html) module lets you create _immutable_ key-value
[associative array](https://en.wikipedia.org/wiki/Associative_array) for your types. More concretely,
OCaml's `Map` module is implemented using a binary search tree algorithm to support fast lookups (of O(Log n)).
OCaml's `Map` module is implemented using a [self-balancing binary search tree
algorithm](https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree)
to support fast lookups (of O(Log n)).

**Note**: The concept of a `Map` in this tutorial refers to a data structure that stores a
set of key-value pairs. It is sometimes called a dictionary or an association table. This
Expand All @@ -26,6 +28,13 @@ the maps, and a function for comparing them.
For a different implementation of an association table in OCaml's Standard Library, see the tutorial
on [Hash Tables](/docs/hash-tables).

`Map` offers a functional interface that `Hashtbl` does not.
`Map` also maintain total ordering of the keys, allowing more operations;
while hash tables have better search performance on average.
For more on their differences and the applications of Maps, see the corresponding
paragraph on wikipedia: [applications of balanced binary search
trees](https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree#Applications).

```ocaml
# module StringMap = Map.Make(String);;

Expand Down
6 changes: 6 additions & 0 deletions data/tutorials/language/3ds_04_hashtbl.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ logarithmic time complexity (O(log n)), a [`hash
table`](https://en.wikipedia.org/wiki/Hash_table) is able to retrieve
information at a nearly instantaneous constant time complexity (O(1)).

**Note:** For more details on the differences between hash tables and associative maps,
see [comparisons of associative array
implementations](https://en.wikipedia.org/wiki/Associative_array#Comparison).
OCaml Maps use [self-balancing binary search
trees](https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree).

A hash table data structure achieves efficient reads and writes by employing a
hashing function that converts the key of a key/value pair into an
algorithmically unique "fingerprint" known as a hash. OCaml has a built-in
Expand Down
Loading