c++ code for generating codebook