Skip to content

mkamensky/List-Sorted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

List::Sorted - Class representing a list that is always sorted

VERSION

version 0.001

SYNOPSIS

my $l = new List::Sorted;
$l->insert(2,1,3);
say $l->[1]; # says 2

DESCRIPTION

This class represents a list that remains sorted.

METHODS

new

$l = new List::Sorted [ccmp => sub {...}];

Create a new object. If ccmp is given, it should be a coderef that compares two elements in the list (as in the comparator argument in List::BinarySearch). If it is not given, it defaults to the class's "ccmp" method (which can be overriden in derived classes).

ccmp

if ( $self->ccmp($a,$b) ) { ... }

The method used to compare elements for sorting.

find_pos

$pos = $self->find_pos($i)

Find the position of the argument $i in the list. If the element is not in the list, finds the place where it can be inserted to keep the list sorted.

insert

$self->insert(3,1,2);

Insert the given elements into the list, keeping it sorted. Returns the list.

store

$err = $self->store("foo.yml", 0.1);

Store the content of the list in the given file. The second argument is a data version, which should be changed when the structure of the elements stored in the list changes.

Returns the error, if any. This method requires YAML::Any.

load

$err = $self->load("foo.yml", 0.1);

Load the content of the list from the given file, assuming the data version in the file is exactly the one given. Any previous content of $self is removed. Returns the error, if any.

This method requires YAML::Any.

OVERLOADING

# get a List::Sorted $l
my @data = @$l; # @data is a regular (sorted) array

Objects can be dereferenced to obtain the underlying array. Note that this should not be used to modify the array, since the list must remain sorted.

SEE ALSO

List::BinarySearch, YAML::Any

AUTHOR

Moshe Kamensky kamensky@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Moshe Kamensky.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

About

Class representing a list that is always sorted

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages