It appears that
a. There are going to be a very large number of DataStruct and Action objects (since the memory footprint of DataStruct is quite small).
b. DataStruct objects are added, but never removed (since the key is based on the size of the map).
In that case, using both a std::map<> and a std::set<> is unnecessary; a std::vector<> (with the key as the position in the sequence) and a std::set<> would suffice.
Something like this:
struct DataStruct
{
double xData, yData ;
std::vector<DataStruct>::size_type keyVal ;
friend bool operator< ( const DataStruct& a, const DataStruct& b ) ;
};
class MapClass
{
static std::vector<DataStruct> seq ;
static std::set<DataStruct> set ;
public:
typedef std::vector<DataStruct>::size_type pos_t ;
static pos_t AddDataStruct( const DataStruct& ds )
{
auto iterator = set.find( ds ) ;
if( iterator != set.end() ) return iterator->keyVal ;
else
{
pos_t pos = seq.size() ;
seq.push_back(ds) ;
seq.back().keyVal = pos ;
set.insert( seq.back() ) ;
return pos ;
}
}
static const DataStruct& get( pos_t pos ) { return seq[pos] ; }
};
class Action
{
MapClass::pos_t dataKey ;
void do_stuff()
{
const DataStruct& ds = MapClass::get(dataKey) ;
// ...
}
};
with some additional trickery, more memory can be saved - make the value_type of the std::set<> a position in the sequence held by std::vector<>
If Datastruct objects also need to be removed as the program is running, this won't work; you could use boost::bimap<> in that case.
http://www.boost.org/doc/libs/1_47_0/libs/bimap/doc/html/index.html