index

// Generate Binary Numbers

typedef unsigned int uint;

map< uint, vector<bool> > IncrementBinaryTree(map< uint,  vector<bool> > m);
map< uint, vector<bool> > GenerateBinaryTree(uint nIterations);

map< uint, vector<bool> > IncrementBinaryTree(map< uint, vector<bool> > m)
{
       map< uint,  vector<bool> >::iterator i;
       map< uint,  vector<bool> > mNext;

       for(i = m.begin(); i != m.end(); i++)
       {
           uint n          = i->first;
           vector<bool> vB = i->second;

           uint n1 = n;
           uint n2 = n;

           n1 *= 2;
           n2  = n1 + 1;

           vector<bool> vB1 = vB;
           vector<bool> vB2 = vB;

           vB1.push_back(false);
           vB2.push_back(true);

           mNext.insert(make_pair(n1, vB1));
           mNext.insert(make_pair(n2, vB2));
        }

        return mNext;
}

map< uint,  vector<bool> > GenerateBinaryTree(uint nIterations)
{
    uint n0 = 0;
    uint n1 = 1;
    vector<bool> vZero(1,false);
    vector<bool> vOne(1,true);

    map< uint,  vector<bool> > mBinaryTree;

   mBinaryTree.insert(make_pair(n0, vZero));
   mBinaryTree.insert(make_pair(n1, vOne));

  for(uint n = 1; n < nIterations; n++)
  {
      mBinaryTree = cGC.IncrementBinaryTree(mBinaryTree);
  }

   return mBinaryTree;
}