Angus Leeming <[EMAIL PROTECTED]> writes:

| Lars, you have posted the following warning in 
| controllers/ControlMath.C:
| 
| string const find_xpm(string const & name)
| {
| #warning Use a static table for this (Lgb)
|         // And get O(log n) lookup (Lgb)
| 
|         string xpm_name = subst(name, ' ', '_');
|         if (xpm_name == "(") xpm_name = "lparen";
|         else if (xpm_name == ")") xpm_name = "rparen";
|         else if (xpm_name == "[") xpm_name = "lbracket";
|         else if (xpm_name == "]") xpm_name = "rbracket";
|         else if (xpm_name == "{") xpm_name = "lbrace";
|         ...
| 
| Do you mean something like:

actually I think I thought more of using just the xpm_names table and
some std:: binary search algorithm.

Using a std::map for this seems a bit expensive.

struct xpm_struct {
        char key;
        char const * value;
};

string const find_xpm(string const & name)
{
        xpm_struct const xpm_names[] = {
                { "(", "lparen" },
                { ")", "rparen"},
                { "[", "lbracket"},
                { "]", "rbracket"},
                { "{", "lbrace"} };

        size_t const xpm_names_size =
                  sizeof(xpm_names) / sizeof(xpm_struct);


        // here std::lower_bound(xpm_names, xpm_names +
sizeof(xpm_names), name, some_functor);
        // could be used.        
}
 

-- 
        Lgb

Reply via email to