是否有 Perl 模块用于记住散列中键的顺序?
是否存在具有 O(log(n)) 访问时间的基于树的有序键值存储的“规范”(纯)perl 实现?
我尝试在 CPAN 上搜索“tree”,但没有从中获得太多见解。
这个问题激发了我发布自己的问题。
编辑:所以问题表述不清楚。
我正在寻找的是一种存储,它几乎不能完成 %hash 的功能,但以更糟糕的算法复杂性为代价维持其键的顺序。到目前为止,我所知道的所有具有此类属性的结构都是基于某种树(B 树、红黑树等),因此得名。
这是我想看到的伪代码示例:
my $set = Some::Module->new();
$set->store( foo=>1 );
$set->store( bar=>2 );
$set->fetch( "foo" ); # 1
$set->keys(); # bar, foo and not foo, bar
$set->keysBetween( undef, "baz" ); # bar only
Is there a "canonical" (pure-)perl implementation of a tree-based ordered key-value storage with O(log(n)) access time?
I've tried searching for "tree" on CPAN but haven't got much insight from that.
This question inspired me to post my own.
EDIT: So the question was unclearly stated.
What I'm looking for is a storage that barely does what a %hash would do, but maintains the order of its keys at a price of worse algorithmic complexity. All structures with such properties I know so far are based on some kind of tree (B-tree, red-black tree etc), hence the title.
Here's a pseudocode example of what I'd like to see:
my $set = Some::Module->new();
$set->store( foo=>1 );
$set->store( bar=>2 );
$set->fetch( "foo" ); # 1
$set->keys(); # bar, foo and not foo, bar
$set->keysBetween( undef, "baz" ); # bar only
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tie::IxHash
是perlfaq4
建议:如果这个模块不能满足要求,也可以尝试在 CPAN 上搜索“tie hash order”。
Tie::IxHash
is theperlfaq4
recommendation:Also try searching for "tie hash order" on CPAN if this module doesn't cut the mustard.
请参阅
树
。see
Tree
.