#ifndef INCLUDED_CLUSTER_
#define INCLUDED_CLUSTER_

#include <unordered_map>
#include "../err/err.h"
#include "../typeselector/typeselector.h"

class Cluster: private TypeSelector, private Err
{
    struct Prefix               // value of the d_cluster unordered_map
    {
        size_t count = 0;       // # times a switch to this prefix is used
        bool active = false;    // this prefix is currently active
        ConstIterVect vect;     // all elements having the same prefix        
    };    

    using PrefixMap = std::unordered_map<std::string, Prefix>;
    using MapValue = PrefixMap::value_type;
    using MapIter = PrefixMap::iterator;

    std::string const &d_path;

    VectConstIter d_iter;       // iterators to all elements in order.txt
    VectConstIter const &d_end;

    PrefixMap d_map;
    MapIter d_next;

    public:
        Cluster(std::string const &path, 
                VectConstIter const &iter, VectConstIter const &end);
        void inspect();
        VectConstIterPair next();
    private:
        void activate(MapIter const &iter, VectConstIter const &elementIter);
};
        
#endif
