split the working code out from the XS file
[poe-xs-queue-array.git] / Array.pm
CommitLineData
e38f8ec4
TC
1package POE::XS::Queue::Array;
2use strict;
3use vars qw(@ISA $VERSION);
4use POE::Queue;
5
6@ISA = qw(POE::Queue);
7
8BEGIN {
9 require Exporter;
10 @ISA = qw(Exporter);
11 $VERSION = '0.001';
12 eval {
13 # try XSLoader first, DynaLoader has annoying baggage
14 require XSLoader;
15 XSLoader::load('POE::XS::Queue::Array' => $VERSION);
16 1;
17 } or do {
18 require DynaLoader;
19 push @ISA, 'DynaLoader';
20 bootstrap POE::XS::Queue::Array $VERSION;
21 }
22}
23
24# lifted from POE::Queue::Array
25sub ITEM_PRIORITY () { 0 }
26sub ITEM_ID () { 1 }
27sub ITEM_PAYLOAD () { 2 }
28
29sub import {
30 my $package = caller();
31 no strict 'refs';
32 *{ $package . '::ITEM_PRIORITY' } = \&ITEM_PRIORITY;
33 *{ $package . '::ITEM_ID' } = \&ITEM_ID;
34 *{ $package . '::ITEM_PAYLOAD' } = \&ITEM_PAYLOAD;
35}
36
37# everything else is XS
381;
39
40__END__
41
42=head1 NAME
43
44POE::XS::Queue::Array - an XS implementation of POE::Queue::Array.
45
46=head1 SYNOPSIS
47
48See POE::Queue.
49
50=head1 DESCRIPTION
51
52This class is an implementation of the abstract POE::Queue interface.
53It implements a priority queue using C, with an XS interface supplied.
54
55The current implementation could use some optimization, especially for
56large queues.
57
58Please see the POE::Queue documentation, which explainsthis one's
59functions, features, and behavior.
60
61=head1 SEE ALSO
62
63POE, POE::Queue, POE::Queue::Array
64
65=head1 BUGS
66
67None known.
68
69Some possible improvements include:
70
71=over
72
73=item *
74
75use binary searches for large queues
76
77=item *
78
79use a B-Tree for the queue (not a binary tree, a B-Tree), though this
80would require a module rename.
81
82=item *
83
84use a custom hash instead of a HV for the id to priority mapping,
85either glib's hash or convert to C++ and use the STL map.
86
87=item *
88
89some of the XS code could be optimized to do less work in scalar
90context, pq_remove_items and pq_peek_items could avoid building all
91those array refs.
92
93=back
94
95=head1 AUTHOR
96
97Tony Cook <tonyc@cpan.org>
98
99=cut
100
101