void StringIntern::set(const char* s, size_t size){ bool has_lock = false; TrieNode** curr= & root(); TrieNode* last=NULL; size_t i = 0; while(i<size){ if(*curr){ char let = (*curr)->letter; if(s[i]<let)curr= &(*curr)->less; else if(s[i]>let)curr= &(*curr)->greater; else{ last=*curr; curr= &(*curr)->equal; ++i; } }else{ if(has_lock){ *curr = new TrieNode(s[i],last); ++i; last=*curr; curr=&last->equal; }else{ create_m().lock(); has_lock=true; } } } data=last; if(has_lock)create_m().unlock(); }
int main(int argc, char const* const argv[]) { check_argv(argc, argv); std::string mode(argv[1]); if(mode == "encode") { return encode_to_file(create_m(), "test21.c2ml.data"); } else if(mode == "decode") { M m; validate_decode(m, "test21.ml2c.data"); } else { std::cerr << "Invalid second argument: " << argv[1] << std::endl; return 1; } }