runnig

word ladder 8 char max

Apr 3rd, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. typedef int word_id;
  2. typedef unordered_multimap<uint64_t, word_id> graph_t;
  3.  
  4. void build_graph(graph_t & G, vector<string> words)
  5. {
  6.     uint64_t basket = 0;
  7.     for(int w_id = 0; w_id < words.size(); ++w_id)
  8.     {
  9.         const string & S = words[i];
  10.         const size_t L = S.length();
  11.        
  12.         assert(L <= 8);
  13.        
  14.         uint64_t word = *((uint64_t*)S.c_str());
  15.         for(int ch = 0; ch < L; ++ch)
  16.         {
  17.             uint64_t mask = &(0xFF << (ch * 8));
  18.             basket = mask & word;
  19.            
  20.             G.insert(basket, w_id);
  21.         }
  22.     }  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment