Simple dictionary in C++

前端 未结 8 1211

Moving some code from Python to C++.

BASEPAIRS = { \"T\": \"A\", \"A\": \"T\", \"G\": \"C\", \"C\": \"G\" }

Thinking maps might be overkill? W

8条回答
  •  情深已故
    2021-01-30 17:02

    Until I was really concerned about performance, I would use a function, that takes a base and returns its match:

    char base_pair(char base)
    {
        switch(base) {
            case 'T': return 'A';
            ... etc
            default: // handle error
        }
    }
    

    If I was concerned about performance, I would define a base as one fourth of a byte. 0 would represent A, 1 would represent G, 2 would represent C, and 3 would represent T. Then I would pack 4 bases into a byte, and to get their pairs, I would simply take the complement.

提交回复
热议问题