Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sysread/p6-algorithm-skewheap
An efficient and flexible min heap algorithm for perl6
https://github.com/sysread/p6-algorithm-skewheap
data-structures heap perl6 priority-queue skew-heap
Last synced: 15 days ago
JSON representation
An efficient and flexible min heap algorithm for perl6
- Host: GitHub
- URL: https://github.com/sysread/p6-algorithm-skewheap
- Owner: sysread
- License: artistic-2.0
- Created: 2018-10-24T17:32:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-06T13:53:11.000Z (about 5 years ago)
- Last Synced: 2024-10-11T20:43:03.611Z (about 1 month ago)
- Topics: data-structures, heap, perl6, priority-queue, skew-heap
- Language: Perl 6
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
NAME
====Algorithm::SkewHeap - a mergable min heap
VERSION
=======0.0.1
SYNOPSIS
========use Algorithm::SkewHeap;
my $heap = Algorithm::SkewHeap.new;
for (1 .. 1000).pick(1000) -> $n {
$heap.put($n);
}until $heap.is-empty {
my $n = $heap.take;
}$heap.merge($other-heap);
DESCRIPTION
===========A skew heap is a type of heap based on a binary tree in which all operations are based on merging subtrees, making it possible to quickly combine multiple heaps, while still retaining speed and efficiency. Ammortized performance is O(log n) or better (see [https://en.wikipedia.org/wiki/Skew_heap](https://en.wikipedia.org/wiki/Skew_heap)).
SORTING
=======Items in the heap are returned with the lowest first. Comparisons are done with the greater than operator, which may be overloaded as needed for types intended to be used in the heap.
class Algorithm::SkewHeap
-------------------------SkewHeap class
### method size
```perl6
method size() returns Int
```Returns the number of items in the heap
### method is-empty
```perl6
method is-empty() returns Bool
```Returns true when the heap is empty
### method top
```perl6
method top() returns Any
```Returns the top item in the heap without removing it.
### method take
```perl6
method take() returns Any
```Removes and returns the top item in the heap.
### method put
```perl6
method put(
$value
) returns Int
```Adds a new item to the heap. Returns the new size of the heap.
### method merge
```perl6
method merge(
Algorithm::SkewHeap $other
) returns Int
```Destructively merges with another heap. The other heap should be considered unusable afterward. Returns the new size of the heap.
### method explain
```perl6
method explain() returns Nil
```Prints the structure of the heap for debugging purposes.