1 package Tie
::Hash
::Sorted
::XS
;
7 use Tree
::SizeBalanced
;
9 our $VERSION = '0.000_001';
12 my ($class, $tree) = @_;
13 $tree //= Tree
::SizeBalanced
::str_any
->new;
18 my ($self, $key) = @_;
19 my ($k, $v) = $$self->find($key);
24 my ($self, $key, $value) = @_;
26 $$self->insert($key, $value);
30 my ($self, $key) = @_;
34 # sub CLEAR unimplemented
37 my ($self, $key) = @_;
38 my @list = $$self->find($key);
48 my ($self, $lastkey) = @_;
49 $$self->find_gt($lastkey);
64 Tie::Hash::Sorted::XS - hash with ordered keys backed by binary search tree
68 use Tie::Hash::Sorted::XS;
70 tie my %hash, 'Tie::Hash::Sorted::XS';
76 my $keys = join ' ', keys %hash;
78 is $keys, 'Anna Bob Jim', 'keys are ordered';
79 is $hash{Bob}, 3, 'retrieval works';
83 This module is not yet fully implemented. Current limitations include
84 the CLEAR function not being implemented (meaning it is impossible to
85 assign a list to a tied hash) and iteration being slow (O(n log n) to
86 iterate over the whole hash). The latter is due to lack of suitable
87 methods in the underlying L<Tree::SizeBalanced>.
89 L<Tree::SizeBalanced> is an implementation of a size-balanced tree, a
90 kind of self-balanced binary search tree. This is a data structure
91 similar to a Perl hash that permits O(log n) insertion, deletion, and
92 random access while keeping the keys sorted.
94 This module is a C<tie> interface to L<Tree::SizeBalanced>. It allows
95 one to create a hash that is implemented by a L<Tree::SizeBalanced>.
96 These hashes should work similarly to regular Perl hashes except that
97 keys will be ordered, keys can be any objects (not just strings), and
98 they have different performance characteristics.
100 The module is used by calling the tie function:
104 =item B<tie> my %hash, 'Tie::Hash::Sorted::XS'[, I<$tree>]
106 This ties a brand new hash to a given L<Tree::SizeBalanced> object (or
107 if none is given, C<< Tree::SizeBalanced::str_any->new >> is used).
109 Whenever this hash is iterated, the keys will come ordered.
115 L<Tree::SizeBalanced>, L<http://wcipeg.com/wiki/Size_Balanced_Tree>
119 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
121 =head1 COPYRIGHT AND LICENSE
123 Copyright (C) 2018 by Marius Gavrilescu
125 This library is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself, either Perl version 5.24.3 or,
127 at your option, any later version of Perl 5 you may have available.
This page took 0.024942 seconds and 4 git commands to generate.