Simple dictionary in C++

前端 未结 8 1287

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 16:56

    If you are into optimization, and assuming the input is always one of the four characters, the function below might be worth a try as a replacement for the map:

    char map(const char in)
    { return ((in & 2) ? '\x8a' - in : '\x95' - in); }
    

    It works based on the fact that you are dealing with two symmetric pairs. The conditional works to tell apart the A/T pair from the G/C one ('G' and 'C' happen to have the second-least-significant bit in common). The remaining arithmetics performs the symmetric mapping. It's based on the fact that a = (a + b) - b is true for any a,b.

提交回复
热议问题