collections v0.2.9
Collections
Collections
is a Crystal shard that provides generic data structures like heaps, including:
BinaryHeapMin
: A min-heap implementationBinaryHeapMax
: A max-heap implementation
Installation
Add this to your application's shard.yml
:
dependencies:
collections:
github: Lillevang/collections
version: ~> 0.2.5
Run shards install
Usage
require "collections"
# Min-Heap Example
heap = Collections::BinaryHeapMin(Int32).new
heap.add([10, 20, 5])
puts heap.extract_root! # => 5
# Max-Heap Example
heap = Collections::BinaryHeapMax(Int32).new
heap.add([10, 20, 5])
puts heap.extract_root! # => 20
# Graph Example
graph = Collections::Graph(Int32).new
graph.add_edge(1, 2)
graph.add_edge(1, 3)
puts graph.neighbors(1).map(&.value) # => [2, 3]
# Grid Example
grid = Collections::Grid(Int32).new(3, 3, 0)
grid.set(1, 1, 1) # block a cell
if result = grid.shortest_path({0, 0}, {2, 2})
distance, path = result
puts distance # => 4
grid.print_grid(path)
end
Development
Write code, good code preferred!
Run tests with: crystal spec
Contributing
- Fork it (https://github.com/Lillevang/collections/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
Released under the MIT License. See LICENSE for details.
Contributors
- Lillevang - creator and maintainer
Repository
collections
Owner
Statistic
- 1
- 0
- 0
- 0
- 1
- 2 months ago
- December 16, 2024
License
MIT License
Links
Synced at
Thu, 04 Sep 2025 20:18:33 GMT
Languages