GithubHelp home page GithubHelp logo

sysread / skewheap Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 74 KB

A fast, efficient, self-adjusting heap for Perl, implemented in C

Perl 20.30% Perl 6 18.64% XS 61.06%
perl xs c data-structures heap skew-heap

skewheap's Introduction

NAME

SkewHeap - A fast and flexible heap structure

SYNOPSIS

use SkewHeap;

my $heap = skewheap{ $a <=> $b };
$heap->put(42);
$heap->put(35);
$heap->put(200, 62);

$heap->top;  # 35
$heap->size; # 4

$heap->take; # 35
$heap->take; # 42
$heap->take; # 62
$heap->take; # 200

my $merged_heap = $heap->merge($other_skewheap);

DESCRIPTION

A skew heap is a memory efficient, self-adjusting heap (or priority queue) with an amortized performance of O(log n) (or better). SkewHeap is implemented in C/XS.

The key feature of a skew heap is the ability to quickly and efficiently merge two heaps together.

METHODS

skewheap

Creates a new SkewHeap which will be sorted in ascending order using the comparison subroutine passed in. This sub has the same semantics as Perl's sort, returning -1 if $a < $b, 1 if $a > $b, or 0 if $a == $b.

size

Returns the number of elements in the heap.

top

Returns the next element which would be returned by "take" without removing it from the heap.

put

Inserts one or more new elements into the heap.

take

Removes and returns the next element from the heap.

merge

Non-destructively merges two heaps into a new heap. Returns the new heap.

AUTHOR

Jeff Ober <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Jeff Ober. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

skewheap's People

Contributors

sysread avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.