NAME
Tie::Hash::Sorted::XS - hash with ordered keys backed by binary search tree
SYNOPSIS
use Tie::Hash::Sorted::XS;
tie my %hash, 'Tie::Hash::Sorted::XS';
$hash{Jim} = 5;
$hash{Bob} = 3;
$hash{Anna} = 7;
my $keys = join ' ', keys %hash;
is $keys, 'Anna Bob Jim', 'keys are ordered';
is $hash{Bob}, 3, 'retrieval works';
DESCRIPTION
This module is not yet fully implemented. Current limitations include the CLEAR function not being implemented (meaning it is impossible to assign a list to a tied hash) and iteration being slow (O(n log n) to iterate over the whole hash). The latter is due to lack of suitable methods in the underlying Tree::SizeBalanced.
Tree::SizeBalanced is an implementation of a size-balanced tree, a kind of self-balanced binary search tree. This is a data structure similar to a Perl hash that permits O(log n) insertion, deletion, and random access while keeping the keys sorted.
This module is a tie
interface to Tree::SizeBalanced. It allows one to create a hash that is implemented by a Tree::SizeBalanced. These hashes should work similarly to regular Perl hashes except that keys will be ordered, keys can be any objects (not just strings), and they have different performance characteristics.
The module is used by calling the tie function:
- tie my %hash, 'Tie::Hash::Sorted::XS'[, $tree]
-
This ties a brand new hash to a given Tree::SizeBalanced object (or if none is given,
Tree::SizeBalanced::str_any->new
is used).Whenever this hash is iterated, the keys will come ordered.
SEE ALSO
Tree::SizeBalanced, http://wcipeg.com/wiki/Size_Balanced_Tree
AUTHOR
Marius Gavrilescu, <marius@ieval.ro>
COPYRIGHT AND LICENSE
Copyright (C) 2018 by Marius Gavrilescu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.3 or, at your option, any later version of Perl 5 you may have available.