| 1 |
NAME |
| 2 |
Tie::Array::Sorted - An array which is kept sorted |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Tie::Array::Sorted; |
| 6 |
|
| 7 |
tie @a, "Tie::Array::Sorted", sub { $_[0] <=> $_[1] }; |
| 8 |
|
| 9 |
push @a, 10, 4, 7, 3, 4; |
| 10 |
print "@a"; # "3 4 4 7 10" |
| 11 |
|
| 12 |
DESCRIPTION |
| 13 |
This presents an ordinary array, but is kept sorted. All pushes and |
| 14 |
unshifts cause the elements in question to be inserted in the |
| 15 |
appropriate location to maintain order. |
| 16 |
|
| 17 |
Direct stores ("$a[10] = "wibble"") effectively splice out the original |
| 18 |
value and insert the new element. It's not clear why you'd want to use |
| 19 |
direct stores like that, but this module does the right thing if you do. |
| 20 |
|
| 21 |
If you don't like the ordinary lexical comparator, you can provide your |
| 22 |
own; it should compare the two elements it is given. For instance, a |
| 23 |
numeric comparator would look like this: |
| 24 |
|
| 25 |
tie @a, "Tie::Array::Sorted", sub { $_[0] <=> $_[1] } |
| 26 |
|
| 27 |
Whereas to compare a list of files by their sizes, you'd so something |
| 28 |
like: |
| 29 |
|
| 30 |
tie @a, "Tie::Array::Sorted", sub { -s $_[0] <=> -s $_[1] } |
| 31 |
|
| 32 |
LAZY SORTING |
| 33 |
If you do more stores than fetches, you may find |
| 34 |
Tie::Array::Sorted::Lazy more efficient. |
| 35 |
|
| 36 |
AUTHOR |
| 37 |
Original author: Simon Cozens |
| 38 |
|
| 39 |
Current maintainer: Tony Bowden |
| 40 |
|
| 41 |
BUGS and QUERIES |
| 42 |
Please direct all correspondence regarding this module to: |
| 43 |
[email protected] |
| 44 |
|
| 45 |
This module was originall written as part of the Plucene project. |
| 46 |
However, as Plucene no longer uses this, it is effectively unmaintained. |
| 47 |
|
| 48 |
COPYRIGHT AND LICENSE |
| 49 |
Copyright (C) 2003-2006 Simon Cozens and Tony Bowden. |
| 50 |
|
| 51 |
This program is free software; you can redistribute it and/or modify it under |
| 52 |
the terms of the GNU General Public License; either version 2 of the License, |
| 53 |
or (at your option) any later version. |
| 54 |
|
| 55 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 56 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 57 |
FOR A PARTICULAR PURPOSE. |
| 58 |
|