How to implement container class/collection/managed list

From: Michael C. Davis (mcdavis941_at_knology.net)
Date: 02/18/04


Date: Tue, 17 Feb 2004 18:57:46 -0600
To: beginners@perl.org

Hi list,

Can anyone recommend a CPAN or Perl core module that implements a container
class / collection / managed list or somethign like that. I've found a
couple that I'm about to study now:

        Tie::Collection
        Class::Composite
        Class::Container

Is there such a module that anyone has found especially useful or suitable?

Basically my program has several data structures that, over time, are
beginning to want similar functions. Gathering all the desired functions
and thinking ahead a little (just to try something different) yields the
following list:

        new / destroy
        add, delete, change
        exists
        get
        keys
        num/length
        asList
        makeKey
        merge
        predecessor, successor
        rename / rekey
        sequentialFirst / sequentialLast
        sequentialNext / sequentialPrev
        orderBy / sortBy / sortRoutine
        reindexMode: all-at-once vs as-needed
        keyingMode: unique (could be implemented as hash) vs set (duplicate keys
allowed)
        fromFile
        toFile
        tieFile

I have in mind that all this occurs in memory (speed is important, with
portions of my code nested 8 loops deep and executing a couple million
times). Still, my function list looks an awful lot like database
functionality, and a good solution may be an 'in-memory' form of DBM/DBI
(which is on my list to look at) or something like that. Regardless, a
good class design would hide the 'in-memory/as-file' implementation detail
behind the class's interface, so that all that is transparent to a user of
the class.

Any help very much appreciated.