Menu

1 / 2

HAMT: persistent maps, sets and vectors for Perl

DEV Community: perl·LNATION·5 days ago
#fqb5DFuy
#devtoperl#devto#dev#hamt#node
Reading 0:00
15s threshold

HAMT is a new CPAN distribution that gives Perl three persistent containers: HAMT::Map , HAMT::Set and HAMT::Vector . "Persistent" here means an update never changes the container you call it on. It returns a new one, and the old one stays exactly as it was.

That sounds expensive. With a Perl hash it is: to keep the old version you copy/clone the whole hash, so one change to a 100,000 key hash costs 100,000 copies. HAMT makes the same change by building four or five small nodes, and the new version shares everything else with the old one.

This is useful anywhere a program copies a hash or array only so it can change it safely.

A quick tour

Every update method returns a new container.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.