Skip to content

Commit

Permalink
add some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
schurhammer committed May 7, 2024
1 parent ccdcc81 commit aa1add0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,76 @@ This priority queue is a wrapper around `gleamy/pairing_heap`, providing additio

You may use the pairing heap or other heap structures directly for much of the same functionality.

```gleam
// priotity queue example
import gleam/int
import gleamy/priority_queue as pq
pub fn main() {
let q = pq.from_list([2, 1, 3], int.compare)
let x = pq.peek(q)
// x = Ok(1)
}
```

### Heap

These heaps are min-heaps, providing efficient access to the minimum value based on a given comparison function.


`gleamy/pairing_heap`:

This is the recommended heap structure for most use cases. However, for some non-linear use cases the performance can degrade because of the amortized nature of this structure.


`gleamy/leftist_heap`:

This heap structure has consistent performance across all use cases.

```gleam
// heap example
import gleam/int
import gleamy/pairing_heap as heap
pub fn main() {
let h =
heap.new(int.compare)
|> heap.insert(2)
|> heap.insert(1)
|> heap.insert(3)
let x = heap.find_min(h)
// x = Ok(1)
}
```

### Non-Empty List


`gleamy/non_empty_list`:

Non-Empty list is a list structure that always contains at least one item.


### Map

Maps are used for key-value lookups. Keys are compared with a user-provided comparison function.


`gleamy/map`:

This is a wrapper around `red_black_tree_map` providing additional utility functions.


`gleamy/red_black_tree_map`:

A map based on a red-black balanced tree structure.


### Set

Sets are used to store a collection of items. Items are compared with a user-provided comparison function to remove duplicate values.


`gleamy/set`:

This is a wrapper around `red_black_tree_set` providing additional utility functions.

This is a wrapper around `red_black_tree_set` providing additional utility functions.

`gleamy/red_black_tree_set`:

A set based on a red-black balanced tree structure.


## Installation

This package can be added to your Gleam project:
Expand All @@ -79,4 +96,5 @@ gleam add gleamy_structures
and its documentation can be found at <https://hexdocs.pm/gleamy_structures>.

## Contributions Welcome

Feel free to make PRs, issues, or requests for new data structures and functions :)
6 changes: 2 additions & 4 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name = "gleamy_structures"
version = "0.5.0"
version = "1.0.0"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
licences = ["Apache-2.0"]
description = "Data structures in pure Gleam including tree, heap, non empty list, map, set, and priority queue."
description = "Data structures in pure Gleam! Including tree, heap, non empty list, map, set, and priority queue."
repository = { type = "github", user = "schurhammer", repo = "gleamy_structures" }
links = [{ title = "Website", href = "https://github.com/schurhammer/gleamy_structures" }]

Expand Down

0 comments on commit aa1add0

Please sign in to comment.